How to join multiple tables to get result of query if some table have no record in SQL Server

Last Reply on Dec 20, 2016 03:43 AM By paulrajmca

Posted on Dec 20, 2016 03:18 AM

hi Developers , I want to 7 number of tables in my application and get all the records both Empty and Non Empty tables in a GridView. Four(4) number of tables only i having records in first time. till i have no records in remaining three tablesthen i am add records to 5th table (then 5th value is picked up and show automatically with last 4 tables)then i am add records to 6th table ( then 5th value is picked up and show automatically with last 5 tables)then i am add records to 7th table (then 5th value is picked up and show automatically with last 4 tables) but in First time when i am open the page it should be display all the tables and fields on 7 tables.if there is value available it should show the value otherwise it display Empty value.But the All Columns should be bind in the gridview. because i need to fetch all the tables and all the columns whether null or not null.

select * from tbl_orderreceived qt 
inner join tbl_despatched t6 on qt.enquiryid=t6.enquiryid 
inner join tbl_invoice t7 on t6.enquiryid=t7.enquiryid 
inner join tbl_supplier t8 on t7.enquiryid=t8.enquiryid   
inner join tbl_fr fr on fr.enquiryid=qt.enquiryid 
inner join  tbl_enquiryregister er on er.enquiryid=fr.enquiryid 
inner join tbl_quotation t5 on t5.enquiryid=er.enquiryid 
where t5.status='A' 
order by t5.orderno asc

Above is my query. in my query give correct output.but working only if all the 7tables having the same record na it gives the output. otherwise it gives Empty  Result. Even  if the 7th table only is Null it gives  also Empty  Result. so please suggest me how to i am get all the tables and all the columns whether it is Null or Not Null table. thanking you Paul.S

Posted on Dec 20, 2016 03:20 AM

Hi paulrajmca,

Insted of using inner join use left outer join or right outer join as per your need. Because inner join only gives matched record.


Posted on Dec 20, 2016 03:43 AM

thanks mr.Dharmendr. 

am sorry i just fogot this. so i got some tension. now i got exact output with following querym

select * from tbl_orderreceived qt left outer join tbl_despatched t6 on qt.enquiryid=t6.enquiryid
left outer join tbl_invoice t7 on t6.enquiryid=t7.enquiryid
left outer join tbl_supplier t8 on t7.enquiryid=t8.enquiryid
left outer join tbl_fr fr on fr.enquiryid=qt.enquiryid left outer join
tbl_enquiryregister er on er.enquiryid=fr.enquiryid left outer join tbl_quotation t5 on
t5.enquiryid=er.enquiryid where t5.status='A' order by t5.orderno asc