我有一个姓名John,Rupert,Cassandra,Amy的列表,并且我想获取表中不存在的名称:Cassandra,Amy
我应该如何编写这样的查询?
我的桌子:
+----+--------+-----------+------+
| id | name | address | tele |
+----+--------+-----------+------+
| 1 | Rupert | Somewhere | 022 |
| 2 | John | Doe | 029 |
| 3 | Donald | Armstrong | 021 |
| 4 | Bob | Gates | 022 |
+----+--------+-----------+------+
集合思考。使用UNION ALL将名称添加到结果集中,使用EXCEPT从结果集中删除名称。
select 'John'
union all
select 'Rupert'
union all
select 'Cassandra'
union all
select 'Amy'
except
select name from mytable;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句