sql - Best practice for where clause -


assume have table contract of contracts following fields: contractid, productid, producttype. in table same contractid have 2 possible productid. table populated 2 possible producttype : type1 , type2.

what reason of doing following query in 1 way or in other?

way 1:

 select c1.productid, c2.productid  contract c1 left join contract c2 on c1.contractid=c2.contractid  c1.producttype <>'type2' 

way 2:

 select c1.productid, c2.productid  contract c1 left join contract c2 on c1.contractid=c2.contractid  c1.contractid not in (select contractid contract producttype = 'type2')  

thanks smart answers!

way 1 both easier read , easier db engine optimize.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -