Menu

Löcher in Id-Sequenzen bei einer MySQL-Datenbank finden

Am Beispiel der KnowledgeBase und dem test-Projekt:

SELECT a.id+1 AS start, MIN(b.id) - 1 AS end
FROM kb AS a, kb AS b
WHERE a.id < b.id AND a.project_tag='test' AND b.project_tag='test' 
GROUP BY a.id
HAVING start < MIN(b.id);

Liefert eine Ausgabe in der Art:

| start | end  |
+-------+------+
|     3 |    3 |
|     6 |    6 |
+-------+------+


Dokumenten-ID: kb/993ddb78-727a-4659-8bd1-2f0f2d789857
Package downloaden