黄聪:MYSQL提交一批ID,查询数据库中不存在的ID并返回

假设你数据库有个A表:

ID NAME
    1 aaa
    2 bbb
    3 ccc
    4 ddd

需求:给你几个ID,返回A表中不存在的ID? 例如提交1,2,8,9 返回8,9

select B.id
from (select 1 as id from dual
union
select 2 as id from dual
union
select 8 as id from dual
union
select 9 as id from dual
) B
left join A
on A.id = B.id
where A.id is null;
上一篇:MySql查询结果按照指定顺序排序


下一篇:Servlet概述