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.
| Author |
Topic |
|
sqldba2k6
Posting Yak Master
176 Posts |
Posted - 2007-04-27 : 23:11:10
|
| I have a written a query which is not producing the desired output.Please help me in getting the output.select b.id,emp,city,gender,age from tablea a full outer join tableb b on a.id=b.id Tablea------id emp city ------------ -------------------- ---------- 12345 test1 NY12346 test2 VA12347 test3 MD12348 test4 GA12350 test5 LATableb------id gender age ------------ ------ ---- 12346 M 2012347 M 2512348 F 3012349 M 5612364 F 58I need the below output.id emp city gender age ------------ -------------------- ---------- ------ ---- 12345 test1 NY NULL NULL12346 test2 VA M 2012347 test3 MD M 2512348 test4 GA F 3012350 test5 LA NULL NULL12364 NULL NULL F 5812349 NULL NULL M 56 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-28 : 00:09:22
|
use FULL OUTER JOINselect id = coalesce(a.id, b.id), a.emp, a.city, b.gender, b.agefrom tablea full outer join tableb b on a.id = b.id KH |
 |
|
|
sqldba2k6
Posting Yak Master
176 Posts |
Posted - 2007-04-28 : 09:36:09
|
| Thanks Khtan!!yr query works fine..How about below query which also works but do yu see any problems with the below queryselect z.id, a.emp, a.city, b.gender, b.agefrom(select id from tableAunion select id from tableB) zleft jointableA aon z.id = a.idleft jointableB bon z.id = b.id |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-28 : 10:03:59
|
performance ! You can run both query and check the execution plan KH |
 |
|
|
|
|
|
|
|