本文介绍了在 SQLite 中,如何在一个表中选择不在另一个表中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 SQLite 中有两个表:
I've two tables in SQLite:
Table1:
-------
id
name
Table2:
-------
id
temp_name
我的问题是,如何编写返回 Table2
中不在 Table1
中的名称的 SQL 查询?
My question is, how do I write an SQL query that returns names in Table2
that are not in Table1
?
例如:
Table1:
-------
1, 'john'
2, 'boda',
3, 'cydo',
4, 'linus'
Table2:
-------
1123, 'boda'
2992, 'andy',
9331, 'sille',
2, 'cydo'
在此示例中,SQL 查询应从 Table2
返回元素 andy
和 sille
,因为它们不在 Table1 中.
In this example the SQL query should return elements
andy
, and sille
from Table2
, because they're not in Table1
.
推荐答案
这是在显而易见的"标准 SQL 中的做法:
This is how to do it in "obvious" standard SQL:
select *
from table2
where temp_name not in (select name from table1)
还有其他方法,比如使用
left outer join
,exists
在where
子句中,except
代码>操作.
There are other methods, such as using
left outer join
, exists
in the where
clause, and the except
operation.
这篇关于在 SQLite 中,如何在一个表中选择不在另一个表中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!