return mySQL original row number

前端 未结 1 1409
隐瞒了意图╮
隐瞒了意图╮ 2021-01-25 07:17

I want to get the row_number of the original record in the database. Is there any way to retrieve the original row number of a record in mysql? Suppose my statement is

相关标签:
1条回答
  • 2021-01-25 08:10

    Check: With MySQL, how can I generate a column containing the record index in a table?

    SELECT  c.course_id, 
            @curRow := @curRow + 1 AS row_number
    FROM    course c
    JOIN    (SELECT @curRow := 0) r;
    

    Do note however, this is artificial as the only real 'row number' would be your own primary ID, and every artificial method will change the row number when you change the ORDER clause

    0 讨论(0)
提交回复
热议问题