Skip to content
Advertisement

Syntax Error trying to return row number from database

I’m trying to return the row number of each row (the table named coordonnees with 3 columns: id, x, y), but this code doesn’t work

The error is:

Syntax error near ‘(ORDER BY id), x, y, id

on database : MYSQL 5.7.9

Advertisement

Answer

Apparently, MySQL 5.7 doesn’t support ROW_NUMBER(). However, I found a novel solution that will emulate it at this site.

There are a few caveats, though:

  • The @row_num variable must be set before the @prev_value variable.
  • The first field in the ORDER BY must be the field that you are partitioning by.
  • The default value assigned to the @prev_value variable must not exist in the partition by field.
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement