[英]Sql Left join returns nothing
我希望以所有產品列出的方式加入產品表和訂單表,並顯示當前用戶的所有訂購產品的價格(但是這些價格中的一些是0,因為沒有為該產品提交訂單)。
當用戶確認列表時,將為此列表中的所有產品生成一個invoiceId。 所以在這一步中invoiceId為空(這是我的問題)。
第一個表中有很多產品,但為什么輸出是空的?
表產品:
id | 價錢
表訂單:
id | ProductId | 會員| invoiceId
(我添加了orders.member is null
對於這個問題 orders.member is null
,但沒有機會):
Select * from products left join orders
on products.id=orders.productId
where (orders.member='"&request.cookies("member")&"' or orders.member is null)
and orders.invoiceId is null
編輯:我的猜測:還有其他成員的訂單。 他們是否違反了當前條件 ?
你的病情在第二張桌子上。 因此,它應該在on
子句中:
Select *
from products p left join
orders o
on p.id = o.productId and
o.member='"&request.cookies("member")&"'
where o.invoiceId is null;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.