I am stuck in 1 query.. I want to show all products of customer as well as all sms received by system in 1 Grid/Row. I can achieve this but the thing is to display customer products only I need 3 4 other tables to join with and show all data like product model, customer name etc. this other things comes from other tables.. So I need 2 table to do outer join, and show data from 4 5 tables. I have tried but I failed.
Select tcp.*
, concat(tc.firstname,' ',tc.lastname) as cust_id
, tc.mobile
, tb.brand_name as brand
, tgt.gadget_type as gadget_type
, tm.model_name as model
, ttt.ticket_type as ticket_type
, trs.registration_source as registration_source
From tbl_cust_products tcp
Left Join `tbl_received_sms` trsm on tcp.id = trsm.cust_prod_id
Left Join tbl_customer tc on tcp.cust_id=tc.id
Left Join tbl_brand tb on tcp.brand = tb.id
Left Join tbl_gadget_type tgt on tcp.gadget_type=tgt.id
Left Join tbl_model tm on tcp.model = tm.id
Left Join tbl_ticket_type ttt on tcp.ticket_type=ttt.id
Left Join tbl_registration_source trs on trs.id=tcp.registration_source
Where tcp.del_date is NULL
Union
Select tcp.*
, concat(tc.firstname,' ',tc.lastname) as cust_id
, tc.mobile
, tb.brand_name as brand
, tgt.gadget_type as gadget_type
, tm.model_name as model
, ttt.ticket_type as ticket_type
, trs.registration_source as registration_source
From tbl_cust_products tcp
Right Join `tbl_received_sms` trsm on tcp.id=trsm.cust_prod_id
Left Join tbl_customer tc on tcp.cust_id=tc.id
Left Join tbl_brand tb on tcp.brand=tb.id
Left Join tbl_gadget_type tgt on tcp.gadget_type=tgt.id
Left Join tbl_model tm on tcp.model = tm.id
Left Join tbl_ticket_type ttt on tcp.ticket_type=ttt.id
Left Join tbl_registration_source trs on trs.id=tcp.registration_source
Where tcp.del_date is NULL
in above I want outer join only on tbl_cust_products
and tbl_received_sms
tables. I have tried union for outer join
here. as I searched and find out that MySql do not support direct outer join
like other big database handlers.
If I am making any mistake to use union or any logic plz help me to achieve this..
EDITED
Problem:
In tbl_received_sms
has 7,734 Records and in tbl_cust_products
has 3 Records.. So I need total 7737 Records in result. If I use UNION
only I get 3 Records, If I use UNION ALL
I get 7737 Records but all fields of all records are NULL
.