How do I select all the columns from a table, plus additional columns like ROWNUM?

前端 未结 3 1402
日久生厌
日久生厌 2020-11-28 06:19

In Oracle, it\'s possible to do a SELECT statement that returns the row number as a column in your result set.

For example,

SELECT rownu         


        
相关标签:
3条回答
  • 2020-11-28 06:51

    Qualify the * with the name of the table:

    select rownum, table.* from table
    
    0 讨论(0)
  • 2020-11-28 07:02

    Unfortuantely, i dont think therei s a way to do it, easiest is probably inner join with itself with an inline table of id,count(*), and put an outer select statement

    0 讨论(0)
  • 2020-11-28 07:05

    Dave's answer is great, i'd just like to add that it's also possible to do that by placing the wildcard as the first column:

    select *,rownum from table
    

    Works, but the following won't:

    select rownum,* from table
    

    I've tested on MySQL.

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