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 |
|
siumui
Yak Posting Veteran
54 Posts |
Posted - 2012-03-13 : 20:31:25
|
| Hello all.I want to see if all the id number in a temp table (#idtemp) that does not have a match in either table a or table b. Does the codes below met what I'm trying to achieve?SELECT DISTINCT #idtemp.id AS ID, a.id AS A_ID, b.id AS B_IDFROM #idtempLEFT JOIN employee aON #idtemp.id = a.idLEFT JOIN salary bON #idtemp.id = b.idWHERE a.id IS NULL OR b.id IS NULLPlease help.Thanks.siumui |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-03-13 : 21:27:57
|
[code]SELECT DISTINCT #idtemp.id AS ID , a.id AS A_ID, b.id AS B_IDFROM #idtemp LEFT JOIN employee a ON #idtemp.id = a.id LEFT JOIN salary b ON #idtemp.id = b.idWHERE a.id IS NULL OR b.id IS NULL[/code]OR using not exists[code]SELECT DISTINCT t.idFROM #idtemp tWHERE NOT EXISTS ( SELECT * FROM employee x WHERE x.id = t.id )OR NOT EXISTS ( SELECT * FROM salary x WHERE x.id = t.id )[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|