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 |
|
EnlilCox
Starting Member
3 Posts |
Posted - 2002-09-13 : 06:27:08
|
| I am having a problem with a full outer join.. I am trying to join a table onto itself to get a list of descriptions that match and dont match between two specific IDs. It returns more rows than it should. I have checked the execution plan and it appears to be doing a a join with table a and a.id=101 against all of b and then b and b.id=212 against all of a and joining them together rather than filtering first.Other than using derived tables (with the filtering in, which does solve) is there a better way ?Thanks Stuartselect a.desc, b.descfrom mytable a full outer join mytable b on a.desc = b.desc and b.id=212 and a.id=101 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-09-13 : 06:45:08
|
| not sure what you want.maybeselect a.desc, b.desc from mytable a full outer join mytable b on a.desc = b.desc where (b.id=212 or b.id is null)and (a.id=101 or a.id is null)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
EnlilCox
Starting Member
3 Posts |
Posted - 2002-09-13 : 07:07:04
|
| Ta but it didn't helpThe table is something likePKID ID Desc1 1 Red2 1 Blue3 1 Green4 2 Red5 2 Blue6 2 Yellow7 3 Red8 3 BlueWhat I want isDesc DescRed RedBluw BlueGreen NULLNULL YellowSo its a full outer join or IDs 1 & 2 but not 3 |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-09-13 : 07:20:44
|
| select a.desc, b.desc from mytable a full outer join mytable b on a.desc = b.desc and a.id = 1 and b.id = 2where (b.id = 2 or b.id is null) and (a.id = 1 or a.id is null) ==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|