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
 The join qury,

Author  Topic 

atmonline
Starting Member

14 Posts

Posted - 2008-06-26 : 21:15:51

I have 2 table
sheet1 and sheet2

sheet1 has cloumns
appreq,reqkey,reqdate etc...
sheet2 has columns
appreq,reqkey,reqdate,assignedto

basically both tables almost have same data.but sheet3 has some more rows that are not in sheet4

sheet1

appkey reqkey reqdate
1 100
1 200
2 100
3 200
4 300
4 100
4 200


appkey reqkey reqdate assigneto
1 100 h
1 200 wh
2 100 dsq
3 200 dsq
4 300 dsq
4 100 h


I need help in writing a query whose output should look like this

appkey reqkey assignedto
1 100 h
1 200 wh
2 100 dsq
3 200 dsq
4 300 dsq
4 100 h
4 200 null



Basically i need to combine these 2 tables get the ouptut

i tried the regular join .but its not working


select s1.appkey,s1.reqkey,s2.assignedto
from sheet1 s1 innerjoin sheet2 s2 on sheet1.appkey=sheet2.appkey and sheet1.reqkey=sheet2.reqkey

i know its won't work because there are mutiple records in both tables.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-06-26 : 21:32:29
USE LEFT JOIN
SELECT s1.appkey, s2.reqkey, s2.assignedto
FROM sheet1 s1
left JOIN sheet2 s2
ON s1.appkey = s2.appkey
AND s1.reqkey = s2.reqkey



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -