SQL - Updating ID's efficiently
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 HTML Code:
mytable |
Re: SQL - Updating ID's efficiently
Can you elaborate on what exactly this is for, and what your final goal will be?
Quote:
If I'm the newest (highest number) right now, according to the Unix timestamp / EPOCH field "time", then I should be #1? If then you're the newest in five minutes, then you need to be first, and I need to be #2 ( ... or even a later number )? Quote:
However, if you're solely looking for the current rank (position) of the actual result, at the time of a SELECT query, you can use e.g.: Code:
SET @position=0; SELECT (@position:=@position+1) AS _position, time FROM mytable ORDER BY time DESC; |
Re: SQL - Updating ID's efficiently
Quote:
My workaround for that is now that i made a http request via SteamWorks to my apache server which handles this task. |
Re: SQL - Updating ID's efficiently
You can create your ID column in the db as autoincrement.
Then when you do your insert you just insert the time column and the DB automaticially handles the ID column. For SQLite see this. https://www.tutorialspoint.com/sqlit...oincrement.htm |
All times are GMT -4. The time now is 10:06. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.