0

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

ThisGuy
  • 1,405
  • 1
  • 24
  • 51

1 Answers1

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?

Community
  • 1
  • 1
cyprien
  • 65
  • 6