July 29, 2005 at 12:37 am
Hi
Is there a way to get all the items present in one table and not in other table
So if we take query in northwind database in sql server
Select * from orders where orderid not in (select orderid from [order details])
But can above query be converted to join statement?
Thanks
Amrita
July 29, 2005 at 1:21 am
Try
Select * from orders o left join [order details] od
on o.orderid = od.orderid
where od.orderid is null
July 29, 2005 at 1:22 am
Select a.*,b.OrderId
From Orders a(NoLock)
Left Outer Join [Order Details] b(NoLock) On (a.OrderId = b.OrderId)
Where b.OrderId Is Null
July 29, 2005 at 1:41 am
Hi venku,
Just a comment here, y to use NOLOCK hint, i think sql Query Optimizer will choose the best hints so y to override the default behaviour and by the way NOLOCK hint means "dirty reads" are possible.
Correct me if I'm wrong..
Regards,
Dilip
July 29, 2005 at 2:55 am
Sorry for the use of NoLock, currently I am working on a reporting system and addicted to it.
Yeah, you can avoid using NoLock.
Regards,
Venku
July 29, 2005 at 3:19 am
hey it's ok buddy..sometimes same happens to me too 😉
July 29, 2005 at 4:51 am
thnx for the answers
another question here, which one is better in terms of performance
ie subquery or left outer join
i have read subqueries are slow but in this case left outer join is show in execution plan
ny ideas??
amrita
July 29, 2005 at 5:12 am
Hi Amrita,
Say, ur orders and orderdetail tables grow tremendously in that case anytimes joins would be better than subqueries..Becoz for a subquery for each outer query it will execute the inner query that many times whether you like it or not, e,g. your Orders table have say 1000 records and OrderDetails have 20000 recs. so for each outer query it will execute the innerquery having 20000 recs...can u just paste the execution plans results out here so that we can have a look?
Regards,
Dilip
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply