ADO/ADO.NET - how to join 4 or 5 table using left outer join

Asked By mani on 18-May-12 06:51 AM
hi..i have  maorethan 4 table and need to join using left outer join..
any help???
Somesh Yadav replied to mani on 18-May-12 06:59 AM

How about this:

var loj = (from prsn in db.People
           join co
in db.Companies on prsn.Person_ID equals co.Person_ID
           join prod
in db.Products on prsn.Person_ID equals prod.Person_ID into prods
           
from x in prods.DefaultIfEmpty()
           
select new { Person = prsn.NAME, Company = co.NAME, Product = x.NAME })
mani replied to Somesh Yadav on 18-May-12 07:02 AM
hi..i cant understand u r qerry..
just in need to select data from 5 table using left outer join ???
S K replied to mani on 18-May-12 07:03 AM
You can join any number of table using left outer join only the matter one column should be common in between two 
eg

Select t1.*, t2.* ,t3.*, t4.*   From tablename t1 LEFT OUTER JOIN tablename2 ON  t1.id = t2.id
LEFT OUTER JOIN tablename3 t3 ON  t3.Catid = t1.Catid 
LEFT OUTER JOIN tablename4 t4 ON  t4.Groupid = t3.Gropupid 
LEFT OUTER JOIN tablename5 t5 ON  t5.Otherid = t4.otherid 

hope this helps you