How can I do a MySQL statement that gives off a numbering column based on the ordered criteria? For example, with the use of variables I have been able to produce such column, but the numbering process occurs before it is ordered so the results look in return... out of order
Asked
Active
Viewed 69 times
1 Answers
0
Try to add a counter:
SELECT t.field, t.fieldbis
@curRow := @curRow + 1 AS row_number
FROM table l
JOIN (SELECT @curRow := 0) r
WHERE t.field > 50
ORDER BY t.field2
See With MySQL, how can I generate a column containing the record index in a table?