Return the nth record from MySQL query

SELECT * FROM table ORDER BY ID LIMIT n-1,1

It says return one record starting at record n.


The accepted answer was wrong by 1 before the edit, because the offset is zero-indexed.

From the doc:

With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15

So the correct query would be

SELECT * FROM table ORDER BY ID LIMIT n-1,1

for example "LIMIT 10, 5", it will skip the number of records indicated by the first number and then show the number of records indicated by the second number. In other words it's "LIMIT skip, show".

SELECT * FROM tblTesting LIMIT 3, 6

will display from 4th record to 9th record, total records displayed 6

if you want show descending order use DESC

SELECT * FROM tblTesting ORDER BY column_name DESC LIMIT 3, 6

Use the limit clause (add 'limit 3, 1' to the end of your query to only select the third row).

Here's some more information: http://php.about.com/od/mysqlcommands/g/Limit_sql.htm


MYSQL: The offset always start from zero-indexed

OFFSET value means not start from OFFSET value

Example: records 1, 2, 3, 4, 5.

OFFSET 1 means return 2nd value, as OFFSET 2 return 3rd value and so on

SELECT table_column FROM Table GROUP BY table_column DESC LIMIT 1 OFFSET 1;

OR

SELECT table_column FROM Table GROUP BY table_column DESC LIMIT 3 OFFSET 1;

It will return 3 records from 2nd record