SELECT Id, Name, Lastname
FROM customers AS c, Places AS p,
WHERE c.customer_ID = p.customer_ID
我的问题是,我想阻止查询的结果显示另一个表(阶段)中存在的行
答案 0 :(得分:6)
您可以执行LEFT JOIN并检查是否为空。
SELECT Id, Name, Lastname
FROM customers AS c LEFT JOIN Places AS p ON c.customer_ID = p.customer_ID
WHERE p.customer_ID IS NULL
答案 1 :(得分:1)
添加
and not exists
(subquery to select your exclusions)
到您的查询
答案 2 :(得分:0)
您可以使用:
SELECT Id, Name, Lastname
FROM customers AS c JOIN Places AS p USING(customer_ID)
使用in/exists
这是一种更快捷的方式。
答案 3 :(得分:0)
我想你想要这样的东西:
SELECT Id, Name, Lastname
FROM customers,
WHERE customer_ID NOT IN (SELECT customer_ID FROM Places)