472,348 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

how to join 2 tables

hi, all

if i have 2 tables :

table1 (stocks)
Expand|Select|Wrap|Line Numbers
  1. stk_no  stk_date  stk_qty
  2. ------  --------  -------
  3. abcd    20081101       10
  4. abcd    20081115       20
  5. abcd    20081121       15
  6.  
table2 (calendar)
Expand|Select|Wrap|Line Numbers
  1. cal_date  workingday
  2. --------  ----------
  3. ...
  4. 20081101  Y
  5. 20081102  Y
  6. 20081103  N
  7. 20081104  N
  8. ...
  9. 20081130  Y
  10. ...
  11.  
i want to get (stk_date between 20081101 and 20081130, forget workingday)
Expand|Select|Wrap|Line Numbers
  1. stk_no  stk_date  stk_qty
  2. ------  --------  -------
  3. abcd    20081101       10
  4. abcd    20081102       10    <-- stk_qty of 20081101
  5. abcd    20081103       10    <-- stk_qty of 20081101
  6. ...
  7. abcd    20081114       10    <-- stk_qty of 20081101
  8. abcd    20081115       20    
  9. abcd    20081116       20    <-- stk_qty of 20081115
  10. abcd    20081117       20    <-- stk_qty of 20081115
  11. ...
  12. abcd    20081120       20    <-- stk_qty of 20081115
  13. abcd    20081121       15
  14. abcd    20081121       15    <-- stk_qty of 20081121
  15. abcd    20081121       15    <-- stk_qty of 20081121
  16. ...
  17. abcd    20081130       15    <-- stk_qty of 20081121
  18.  
how to write a select statement without stored-functions.

thanks in advance.
Jan 16 '09 #1
5 1892
sorry, some were mis-typed ( part of "want to get")

stk_no stk_date stk_qty
------ -------- -------
abcd 20081101 10
abcd 20081102 10 <-- stk_qty of 20081101
abcd 20081103 10 <-- stk_qty of 20081101
...
abcd 20081114 10 <-- stk_qty of 20081101
abcd 20081115 20
abcd 20081116 20 <-- stk_qty of 20081115
abcd 20081117 20 <-- stk_qty of 20081115
...
abcd 20081120 20 <-- stk_qty of 20081115
abcd 20081121 15
abcd 20081122 15 <-- stk_qty of 20081121
abcd 20081123 15 <-- stk_qty of 20081121
...
abcd 20081130 15 <-- stk_qty of 20081121
Jan 16 '09 #2
debasisdas
8,127 Expert 4TB
You do not need to join the tables for that.

what is the query that you are working on ?
Jan 16 '09 #3
hi,

if i use table1 only, how do i generate
the records having stk_date between '20081102' and '20081114' ?
(i only have 3 records -- ie. 20081101, 20081115, 20081121 -- in table1 as described)

my query string seemed to be (what i tried was more complicated, so i simplified it):
select table1.stk_no, table2.cal_date, table1.stk_qty
from table2, table1
where table2.cal_date=table1.stk_date(+)
and table2.cal_date between '20081101' and '20081130'

currently, i'm trying the LAG function.

thank you.
Jan 17 '09 #4
Pilgrim333
127 100+
@st33chen
Hi,

The following should be sufficient, you do not need the join:

Expand|Select|Wrap|Line Numbers
  1. select table1.stk_no
  2.      , table1.stk_date
  3.      , table1.stk_qty
  4. from table1
  5. where table1.stk_date between '20081101' 
  6.                           and '20081130'
  7.  
Pilgrim.
Jan 23 '09 #5
hii try finding the other way through oracle site so that ul learn more
Feb 19 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would...
0
by: Soefara | last post by:
Dear Sirs, I am experiencing strange results when trying to optimize a LEFT JOIN on 3 tables using MySQL. Given 3 tables A, B, C such as the...
1
by: TeleTech1212 | last post by:
I am trying to select specific columns from multiple tables based on a common identifier found in each table. For example, the three tables: ...
8
by: Matt | last post by:
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive...
4
by: Anthony Robinson | last post by:
I was actually just wondering if someone could possibly take a look and tell me what I may be doing wrong in this query? I keep getting ambiguous...
2
by: dskillingstad | last post by:
I would really appreciate someone's help on this, or at least point me in the right direction.... I'm working on a permit database that contains...
2
by: Bennett Haselton | last post by:
I know how to create a DataAdapter that loads data from a data source into a table in a typed DataSet, and how to set the DataSource and DataMember...
7
by: Shanimal | last post by:
I would like to know how to join 2 queries so that the results of these 2 queries show up in the same query: SELECT b.bios_serial_number FROM...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the...
3
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.