Mysql 如何获取(我的)SQL表中不存在的ID列表?
我有一个MySQL表,如下所示:Mysql 如何获取(我的)SQL表中不存在的ID列表?,mysql,sql,select,Mysql,Sql,Select,我有一个MySQL表,如下所示: +----+ | id | +----+ | a | | c | | e | +----+ select ids.id from (select 'a' as id union all select 'b' union all select 'c' union all select 'd' union all select 'e' ) ids where ids.id not in (select id from t); 我想检查
+----+
| id |
+----+
| a |
| c |
| e |
+----+
select ids.id
from (select 'a' as id union all select 'b' union all select 'c' union all
select 'd' union all select 'e'
) ids
where ids.id not in (select id from t);
我想检查以下哪个IDa
,b
,c
,d
,e
在表中不存在
也就是说,我想得到一个idb
和d
的列表
我是否可以手工构造一个查询,返回我的表中不存在的ID列表,而不实际创建新的第二个永久SQL表?这通常使用
左连接或类似的方法来完成:
+----+
| id |
+----+
| a |
| c |
| e |
+----+
select ids.id
from (select 'a' as id union all select 'b' union all select 'c' union all
select 'd' union all select 'e'
) ids
where ids.id not in (select id from t);
如果列表已经在表中,则可以使用该表(或子查询)而不是派生表。使用哪个RDBMS…?作为标题和指定的问题;MySQL=)