I'm trying to figure out which is the more efficient way to get the nth highest record in a mySQL database:
SELECT *
FROM table_name
ORDER BY column_name DESC
LIMIT n - 1, 1
or
SELECT *
FROM table_name AS a
WHERE n - 1 = (
SELECT COUNT(primary_key_column)
FROM products b
WHERE b.column_name > a. column_name)
There is an index on column_name.
I would think mySQL would efficiently perform the limit clause and the first option is the way to go.
I wasn't too clear what the 2nd query does exactly, so if that is more efficient can someone explain why.
Thanks.