Skip to content

Instantly share code, notes, and snippets.

@ajaxray
Last active May 15, 2018 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajaxray/4ba0d9e2700d561e2bb00a39e35a61da to your computer and use it in GitHub Desktop.
Save ajaxray/4ba0d9e2700d561e2bb00a39e35a61da to your computer and use it in GitHub Desktop.
Adding row sequence number to MySQl result
SELECT
@a:=@a+1 AS sl,
t.field_name,
ot.other_field_name,
-- more fields...
FROM
(SELECT @a:= 0) AS a,
primary_table_name t
JOIN other_table ot ON t.other_id = ot.id
WHERE
-- conditions...
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment