php – How to write a sql query to number the records in the order in the table?

Question:

How to make a sql mysql query to number the records in order in the table in a pre-prepared column ?

It is desirable 1 request if it is real.

Answer:

update table set field=@num:=@num+1
 where 0 in(select @num:=0)

Numbering will start from 1. If desired, you can adjust the starting value and the method for calculating the next

Scroll to Top