Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL JOIN

Author  Topic 

Alemao
Starting Member

3 Posts

Posted - 2007-01-24 : 04:47:37
Good day Sql Yodas

I have two tables store_information and sales_information as shown below how can I write a join query so that I can get results based on Sales_information table structure like so :

Table New_Information
S/N store_name Expenditure Date Type
1 Los Angeles $1500 Jan-05-1999 Cash
2 San Diego $250 Jan-07-1999 Cheque
3 Los Angeles $300 Jan-08-1999 Cheque
4 Boston $700 Jan-08-1999 Cash



Below are the two tables




Table Store_Information
S/N store_name Expenditure Date
1 Los Angeles $1500 Jan-05-1999
2 San Diego $250 Jan-07-1999
3 Los Angeles $300 Jan-08-1999
4 Boston $700 Jan-08-1999




Table Sales_Information
S/N store_name Sales Type
1 Los Angeles $1500 Cash
2 San Diego $250 Cheque
3 Los Angeles $300 Cheque
4 Boston $700 Cash
5 New York $900 Cheque
6 Chicago $300 Cheque
7 Atlanta $250 Cash

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-24 : 05:07:38
[code]
select a.sn, a.store_name, a.expenditure, a.date, b.type
from Store_Information a inner join Sales_Information b
on a.store_name = b.store_name
[/code]


KH

Go to Top of Page

Alemao
Starting Member

3 Posts

Posted - 2007-01-24 : 06:09:08
Thanks for ur response Khtan I forgot to mention to you that store_ information and sales_information are views after use ur queries what I got are duplicated values
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-24 : 06:29:52
try this...

select a.sn, a.store_name, a.expenditure, a.date, b.type
from Store_Information a inner join Sales_Information b
on a.store_name = b.store_name
and a.sno = b.sno



KH

Go to Top of Page

Alemao
Starting Member

3 Posts

Posted - 2007-01-24 : 06:56:29
Khtan, youre a great guy and a smart one you just resolve 3 days of sleepless night you resolve this sub queries issue. I really appreciate your patience and support.

I am so far away if not I will give you my pretty sister for keeps.Everyone on the Forum Khtan ROCKS !!!!!!!!!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-24 : 18:12:28
Only 3 days?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -