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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 join statement

Author  Topic 

scottichrosaviakosmos
Yak Posting Veteran

66 Posts

Posted - 2011-05-26 : 08:57:45

i have 2 table let say table A and table B.

A have values 1,2,3
B has values 1,2,4

i want query using joins which give all values like:
1
2
3
4
normally joins fetch matching or non matching data .. but how to get over this.
And this has to be achieved only by joins.

scoo

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-05-26 : 09:02:11
[code]select col from A union select col from B[/code]


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

Go to Top of Page

scottichrosaviakosmos
Yak Posting Veteran

66 Posts

Posted - 2011-05-26 : 10:14:42
Thank you , but i think i have written that this should be done by joins only. SO only joins.

scoo
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-05-26 : 10:28:58
then use FULL OUTER JOIN


select col = coalesce(a.col, b.col)
from tablea a full outer join tableb b on a.col = b.col



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

Go to Top of Page
   

- Advertisement -