我有以下有关在SQL中将表连接在一起的问题:
列出未在products
上出售的所有13.05.2003
。考虑表Orders
,LineItem
和Product
。
我编码的是以下内容:
SELECT p.Pid, p.Label
from Product p natural join line_item l
natural join Orders
where Date <> "2003-05-13"
问题是,当我执行此代码时,它应该显示更多的数据,而且我不确定如何使用join
消除重复项。
提前谢谢您
select *
from product p
where not exists (
select null
from lineitem i
join orders o on o.oid = l.oid and l.pid = p.pid
where date <> "2003-05-13"
)
或者您可以使用NOT IN
:
select *
from product
where pid not in (
select l.pid
from lineitem i
join orders o on o.oid = l.oid
where date <> "2003-05-13"
)