Reputation: 23
I want to retrieve the first data from a table with the following data
if I sort with descending it will produce the following values
and then i run the sql command as follows select id from top order by view desc limit 1
and hope to get the very first id which is id with a value of 1 but the resulting value is id with a value of 4.
maybe there is a solution to get an id with a value of 1?
Upvotes: 0
Views: 24
Reputation: 98388
You can specify multiple sort columns and ascending or descending for each. You want to sort by id ascending within view descending, so:
select id from top order by view desc, id asc limit 1
If you just order by view, you will get some arbitrary one of the ids.
Upvotes: 1