mysql find smallest + unique id available

后端 未结 7 649
忘了有多久
忘了有多久 2020-12-09 02:54

i have a column ID and something like 1000 items, some of then were removed like id=90, id=127, id=326

how can i make a query to look for those availabl

7条回答
  •  春和景丽
    2020-12-09 03:03

    In my personal opinion. Instead of removing the row from the auto increment it would be light years less expensive to have Boolean Column for "Removed" or "Deleted" and for extra security over right the row with blanks while you set the removed flag.

    UPDATE table SET data=" ", removed = TRUE WHERE id = ##
    

    (## is the actual id btw) Then you can

    SELECT * FROM table WHERE removed = TRUE ORDER BY id ASC
    

    This will make your Database perform better and save you dough on servers. Not to mention ensure no nasty errors occur.

提交回复
热议问题