JOIN with Multiple tables

 select A.item_id,A.value as DocID,B.Value as FamilyID,C.value as SDO,D.*

from [Item_Detail](nolock) A

inner join [Item_Detail](nolock) B

on A.item_id = B.item_id

inner join [Item_Detail](nolock) C

on A.item_id = C.item_id

left outer join [Item_Detail](nolock) D 

on A.item_id = D.item_id and D.attribute_id='FC0DAAD6-7820-4DA1-AA77-CCF7780038E9'

--giving at where clause is ok untill unless there is an existing row in the table, if there is no row

--then we wont get the desired result. So better to use 'AND D.attribute_id='FC0DAAD6-7820-4DA1-AA77-CCF7780038E9'' at 'ON CLAUSE' itself even

--if there is some performance issue

where A.item_id = '68687B00-A22D-48A8-83FF-00000536E871'

and A.attribute_id = 'FAA27652-97E8-4FBA-88EB-C77EC82C4109'

and C.attribute_id = '5F859754-9FC4-4072-A054-41BF40F21A3B'

and B.attribute_id = '925412D0-7574-46A6-B3BA-4C1111549456'

Comments

Popular posts from this blog

Understanding Collection and Object Initializer

How to execute Javascript in VS code