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
 best way to do a simple join query

Author  Topic 

rnbguy
Constraint Violating Yak Guru

293 Posts

Posted - 2007-02-28 : 19:43:11
ive seen so many ways to do this, including some using cursors (strange i know)

but i have tableA and tableB i want to show fields from tableA which don't apear in tableB

what is the MOST efficient way to do this

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-28 : 20:27:24
[code]
select *
from tablea a left join tableb b
on a.id = b.id
where b.id is null
[/code]


KH

Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2007-02-28 : 23:38:17
select * from tablea a where a.id not in(select id from tableb)

you can also use not exists. It depends on the nullability of your joins.

As for efficiency - often they will end up with the same execution plan but you can use the query analyser to determine this.
Go to Top of Page
   

- Advertisement -