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 |
|
skillile
Posting Yak Master
208 Posts |
Posted - 2004-05-20 : 23:11:26
|
| Wondering what option in the below example should be used for performace reasons. It looks like Option A performs slightly better but I have seen and used both. Anybody want to comment on why or why not.set nocount oncreate table tblwf ( wfid int primary key)create table tblwf2 ( wfid int primary key)goinsert into tblwfselect 1unionselect 2unionselect 3union select 5unionselect 6goinsert into tblwf2select 1unionselect 2unionselect 3go--option aselect a.wfidfrom tblwf awhere not exists(select 1 from tblwf2 b where a.wfid = b.wfid)--option bselect a.wfidfrom tblwf aleft join tblwf2 b ON a.wfid = b.wfid where b.wfid IS NULLdrop table tblwfdrop table tblwf2goslow down to move faster... |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2004-05-21 : 06:19:37
|
| I think option A is going to outrun option B for smaller resultsets in the subquery. When this gets larger, the JOIN is probably going to be faster since the correlated subquery doesn't have to be evaluated for every row. Not sure if this is really the case though, the only way to find out is to test it. Also guess an index on the join columns should benefit both queries equally.OS |
 |
|
|
|
|
|