0

我正在使用以下查询来获取发票详细信息。因此,即使没有客户注册发票,我也需要获取发票详细信息。所以在这种情况下,cusidfk发票表中的外键为空。那么我怎样才能得到结果集呢?如何在同一结果集中为客户显示 null?

SELECT invoice.invno,invoice.invdate,invoice.invtime,customer.bizname,invoice.addedby,item.nameinsin,invoicedetails.price,invoicedetails.soldprice,invoicedetails.qty,invoicedetails.subtotal,invoicedetails.total,payment.pamt,invoice.tot
FROM invoice, invoicedetails, item, customer, payment
WHERE invoice.invno=invoicedetails.invnofk
  AND invoicedetails.itemfkcode=item.itemcode
  AND customer.cusid=invoice.cusidfk
  AND invoicedetails.invnofk='0000000000005'
  AND invoice.invno=payment.invfkno
4

1 回答 1

3

我建议使用JOINLEFT JOIN不是隐式加入。

SELECT ...
FROM invoice
JOIN invoicedetails ON invoice.invno = invoicedetails.invnofk
JOIN item ON invoicedetails.itemfkcode = item.itemcode
JOIN payment ON invoice.invno = payment.invfkno
LEFT JOIN customer ON customer.cusid = invoice.cusidfk
WHERE invoicedetails.invnofk = '0000000000005'

如果不存在条目,则LEFT JOIN所有customer字段都将是。NULL

于 2013-09-17T15:04:02.403 回答