[英]Exclude items from SQL Result
I may be missing something because I thought this would be a simple task. 我可能会缺少一些东西,因为我认为这将是一个简单的任务。
I wanted to retrieve results that were not included in Table 3. 我想检索表3中未包含的结果。
Any help? 有什么帮助吗?
Table 1 表格1
T1C1 T1C2
1 London
2 New York
3 Paris
4 Cardiff
5 Bradford
6 Sydney
7 Bradford
8 Beijing
9 Cairo
Table 2 表2
T2C1 T2C2
A UK
Table 3 表3
T3C1 T3C2
1 A
4 A
5 A
7 A
Result 结果
T1C1 T1C2
2 New York
3 Paris
6 Sydney
8 Beijing
9 Cairo
select * from Table1 where T1C1 not in (select T3C1 from Table3)
select * from Table1 left join Table2 on T1C1=T3C1 where T3C2 IS NULL
select * from Table1 where not exists (select 1 from Table2 where T1C1=T3C1)
(由Tim Schmelter在评论中建议) You could just use NOT IN; 您可以只使用NOT IN;
SELECT * FROM Table1 WHERE T1C1 NOT IN (
SELECT T1C1 FROM Table3
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.