Can I get the position of a record in a SQL result table?

后端 未结 6 948
日久生厌
日久生厌 2020-12-16 02:35

If I do something like

SELECT * FROM mytable ORDER BY mycolumn ASC;

I get a result table in a specific order.

Is there a way in SQL

6条回答
  •  心在旅途
    2020-12-16 03:09

    There's no way you can tell that without selecting an entire subset of records. If your PK is of integer type, you can

    select count(*) from mytable 
        where id <= 10 -- Record with ID 10
        order by mycolumn asc
    

提交回复
热议问题