0

I have created a database with two tables. The tables have a primary key called feed_id and they have been set to autoincrement. However many entries skip numbers. Please check the eg in the screenshot: http://prntscr.com/o2kj7y Directly after 18 the ID goes to 72.

This is an RSS feed hence I do need auto increment .

What can I do to get that in an order and not skip numbers in between?

odan
  • 4,757
  • 5
  • 20
  • 49
Dev.D
  • 407
  • 2
  • 4
  • 12
  • 1
    Possible duplicate of [MySql upsert and auto-increment causes gaps](https://stackoverflow.com/questions/3679611/mysql-upsert-and-auto-increment-causes-gaps) – Dharman Jun 16 '19 at 17:02

1 Answers1

0

Please if possible provide information: which database you use and also DDL(annotation of column or from the whole table).

Looks like that you have created a lot of rows after ID 18 and after it you remove them, autoincrement in this case will take next not used in the past id, even if row was removed. And it can happen again in the future, because id 18 for example can be also removed. If you just need correctly order sequence of ids, create them on the fly in PHP by output(but id can be different in this case for the same item by different requests to the server).

Anton
  • 86
  • 4
  • I am using a MAMP server- PHPMYADMIN. I am using MYSQL queries in the backend to fetch RSS from a url stored in my database. I have created a functions.php which retrieves the URL using sql and php. Here is a screenshot of my database: http://prntscr.com/o2krlv . I am new to this, please help – Dev.D Jun 16 '19 at 16:50
  • Is it okay for you if by calling functions.php several times the same item can have different ID? But the whole result will be always a correct sequence with IDs 1,2,3,4,5, etc. If yes you can create ids on the fly in php, and do not use ids from DB. – Anton Jun 16 '19 at 17:11