I want to select the first row in a table, order by time (ascending), then delete that row. I don’t want to use two queries since there’s a possibility that another client could select that row before it gets deleted (there will be several machines connected at once from different networks).
I was thinking I could do something like
SELECT * FROM `mytable` ORDER BY `time` LIMIT 1;
DELETE FROM `mytable` ORDER BY `time` LIMIT 1
…but I got an error:
You have an error in your SQL syntax;
check the manual that corresponds to
your MySQL server version for the
right syntax to use near ‘; DELETE *
FROMpendingORDER BYtimeLIMIT
1′ at line 1
What’s the best way to do this? Thanks.
Re your error message (different than in your question):
Looks like an error in your syntax. Try removing the
*. That is,Should work fine.