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
 query problem

Author  Topic 

mavershang
Posting Yak Master

111 Posts

Posted - 2009-04-20 : 15:17:13
Hi all. This forum has helped me out of a bunch of rookie's question. Here is another one.

I have two tables with the same columns.
table a:
pos1 content
1 s
2 g
4 t
...

table b:
pos1 content
1 tt
3 c
4 t
...

now I want to have a table with the corresponding relation between a and b like
a.pos1 a.content b.pos1 b.content
1 s 1 tt
2 g null null
null null 3 c
4 t 4 t

I tried a simple Left Outer Join but only get part of the table I want.

Any suggestion? Thanks

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2009-04-20 : 15:30:47
Try using a full join like so:
select *
from a
full join b on a.pos1 = b.pos1
Go to Top of Page

mavershang
Posting Yak Master

111 Posts

Posted - 2009-04-20 : 15:40:02
Thanks a lot.

quote:
Originally posted by jdaman

Try using a full join like so:
select *
from a
full join b on a.pos1 = b.pos1


Go to Top of Page
   

- Advertisement -