Imagine i had a set of 30 records
for instance
users : {user_id, name, category}
and i did this Query:
SELECT name
FROM users
WHERE category = "Student"
AND id < 30
ORDER BY user_id
LIMIT 5
This would give me the users that have id from 1 to 5
but how about if i wanted to get the highest id values that are less than 30
in this case the desired results would be id’s from 24 -29.
ps. my real problem is a bit more complex than this, i just wanted get the basic theory.
also note that i would of used another AND clause to say > 23, but this wouldnt work with my schema.
You could wrap what Dan J wrote into a set and SELECT from it, then applying an ASC order. Not sure of the MySQL syntax, but in MS SQL it would be:
The ASC is optional.