Add a numbered list column to a returned MySQL query

前端 未结 4 2108
不知归路
不知归路 2021-01-06 01:28

I am trying to get a sequential number column returned with my sql query. I need this to be inside the SELECT statement because I want to nest this query in another, and the

4条回答
  •  無奈伤痛
    2021-01-06 01:32

    You need to use MySQL user variables. Let us take a variable t1. Initialize it at 0. And increment it in every select value.

    SET @t1=0;
    SELECT @t1 := @t1+1 as row_number, my_awesome_table.* from my_awesome_table
    

    This will do the trick.

提交回复
热议问题