SQL Query没有任何连接

时间:2017-11-18 10:08:50

标签: where

下表:

ReviewPicture(rid, pid)
ArticlePicture(aid, pid)
Picture(pid, filename)

我希望在不使用联接的情况下获取既未在ArticlePicture也未在ReviewPicture中使用的图片ID。

这就是我到目前为止所做的 - 不幸的是我在Picture中得到了所有图片:

select distinct Picture.pid
FROM Picture, ReviewPicture, ArticlePicture
where Picture.pid <> ReviewPicture.pid
AND Picture.pid <> ArticlePicture.pid;

1 个答案:

答案 0 :(得分:0)

您可以使用子查询

SELECT DISTINCT Picture.pid FROM Picture
WHERE PID NOT IN (SELECT PID FROM ReviewPicture) AND PID NOT IN (SELECT PID FROM ArticlePicture)