View Single Post
Author Message
xice1337
AlliedModders Donor
Join Date: Dec 2015
Old 08-21-2021 , 11:34   SQL - Updating ID's efficiently
Reply With Quote #1

Hello,
i have a table where i want to fill in numbers for the ID starting from 1 then 2 and so on.
The table is ordered by time so the most recent time should get number 1.

There is a query which works on phpmyadmin but not directly in sourcemod:
SET @i:=0; UPDATE mytable SET ID = @i:=(@i+1) ORDER BY time DESC;

The table before
HTML Code:
mytable
ID                  time
null                1629156967
null                1628735917
null                1628513592
How the result should be:
HTML Code:
mytable
ID                  time
1                   1629156967
2                   1628735917
3                   1628513592
Is there a good way to do this? I dont really wanna loop over every row to achieve this.
xice1337 is offline