Raised This Month: $51 Target: $400
 12% 

SQL - Updating ID's efficiently


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode