在SQL中列出具有连接的数据

问题描述 投票:0回答:1

我有以下有关在SQL中将表连接在一起的问题:

列出未在products上出售的所有13.05.2003。考虑表OrdersLineItemProductenter image description here

我编码的是以下内容:

SELECT p.Pid, p.Label
 from Product p natural join line_item l
natural join Orders
where Date <> "2003-05-13"

问题是,当我执行此代码时,它应该显示更多的数据,而且我不确定如何使用join消除重复项。

提前谢谢您

sql join left-join inner-join right-join
1个回答
0
投票
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"
)
© www.soinside.com 2019 - 2024. All rights reserved.