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 |
|
Tototo1
Starting Member
22 Posts |
Posted - 2012-03-14 : 16:58:32
|
| I am trying to get back data from one table that does not exist in another. I have Table #aaa with 1000 records and table ###b with 400 records. I want to return all values in table #aaa that are not in #bbb. Is there an easy way to do such a query? Thanks! |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-03-14 : 17:06:22
|
| SELECT * FROM #aaaEXCEPTSELECT * FROM ###b |
 |
|
|
Tototo1
Starting Member
22 Posts |
Posted - 2012-03-15 : 10:49:58
|
| Wow that was simple. Thanks! |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-15 : 15:25:38
|
| [code]SELECT * FROM #aaa aWHERE NOT EXISTS(SELECT 1 FROM #bbb WHERE relcol=a.relcol)[/code]relcol should be substitued by column through which tables are related------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|