有了这两张桌子:
table1
----
id(ai) id_aaa
1 1
31 2
32 3
43 5
46 8
table2
----
id record
1 4
我需要一个select给我table1 id_aaa = 6。下一个可用的id aaa,它不存在于table2中的记录中。
答案 0 :(得分:0)
这应该可以解决问题:
SELECT MIN(id_aaa + 1) AS next_one FROM table1 t1
LEFT JOIN table1 t1bis ON t1.id_aaa + 1 = t1bis.id_aaa
WHERE t1bis.id_aaa IS NULL AND id_aaa + 1 NOT IN (SELECT record FROM table2);