Skip to content

Instantly share code, notes, and snippets.

@gadiener
Last active March 22, 2017 15:38
Show Gist options
  • Save gadiener/9d00d205b02b013d17b3817417faa3f6 to your computer and use it in GitHub Desktop.
Save gadiener/9d00d205b02b013d17b3817417faa3f6 to your computer and use it in GitHub Desktop.
Add row number to MySql query
SELECT * FROM
(
SELECT
@i:=@i+1 AS rownum,
subq.*
FROM
(
SELECT id,date FROM articles
) subq,
(SELECT @i:=0) r
ORDER BY date ASC
) _tmp
WHERE rownum > 3
LIMIT 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment