473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 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 1932
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 have passed it, because your queries did help me...
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 following: create table A ( uniqueId int not...
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: PUBACC_AC PUBACC_AM PUBACC_AN each have a...
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 all articles that match a criteria from ar and...
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 column errors and have no idea why...? Thanks in...
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 12 tables, and rather than list all of the...
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 properties of a DataGrid so that at run time it...
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 bios b: SELECT s.system_name FROM system s; ...
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 values of multiple fields - get their possible...
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 table (tblMaster)... I want to perform a query, so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.