SQL show selected rows from multi tables if some columns data missing

94 views Asked by At

I have this query:

SELECT bills.date as bills_date
     , bills.bill_nr as bill_nr
     , bills.amount as amount
     , cheques.cheque_nr as cheque_nr
     , cheques.date as cheque_date
     , cheques.amount as cheque_amount 
FROM bills 
INNER JOIN cheques ON bills.bill_nr = cheques.cheque_nr 
LEFT JOIN companys ON bills.company = companys.id 
WHERE companys.name='';

The problem that this query didn't return bill if it didn't have any cheque. Maybe someone knows how to fix it? Thank you!

1

There are 1 answers

0
M.Ali On BEST ANSWER
SELECT bills.date as bills_date
     , bills.bill_nr as bill_nr
     , bills.amount as amount
     , cheques.cheque_nr as cheque_nr
     , cheques.date as cheque_date
     , cheques.amount as cheque_amount 
FROM  bills
LEFT JOIN cheques   ON bills.bill_nr = cheques.cheque_nr   --<-- LEFT JOIN here
LEFT JOIN companys  ON bills.company = companys.id 
WHERE companys.name='';