Reputation: 10828
I want to find out what is the previous ID, how can that be done?
Find ID 5:
SELECT id FROM status` WHERE id = 5 ORDER BY order_status ASC
Now I want get previous ID depending on ORDER order_status ASC
Upvotes: 1
Views: 236
Reputation: 24815
Use the MAX() function in combination with a WHERE like this:
SELECT MAX(id) FROM status WHERE id < 5
Note the ORDER BY
has no use as you are only selecting one row
Upvotes: 4