且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

sql查询以获取已删除的记录

更新时间:2023-12-04 22:08:16

我认为最简单的方法是创建一个仅包含ID的虚拟/临时表. 1-1000然后左联接到该表.

I think easiest would be to have a dummy/temp table with just ids. 1-1000 then left join to that table.

但是一旦完成,请确保从虚拟/临时表中删除已删除"记录.否则,它们将每次出现.

But be sure to remove the "deleted" records from your dummy/temp table once you're done. Otherwise, they will show up every time.

>>编辑<< 您可以进行自我加入以找出是否缺少ID....

>> EDIT << You can do self join to figure out if you're missing ids....

select a.id + 1 MissingIds
from <table> a
left join <table> b
  on a.id = b.id - 1
where b.id is null
  and a.id < 10000