如果缺少某些列数据,SQL将显示多表中的选定行

时间:2014-11-30 20:44:54

标签: sql select row no-data

我有这个问题:

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='';

如果没有任何检查,此查询未返回帐单的问题。也许有人知道如何解决它?谢谢!

1 个答案:

答案 0 :(得分:1)

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='';