Question

In SQL Server2005, Row_number() function is used to retrieve the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition. Which is very useful when implementing paging through a large number records in Table. Is there any function available in SQLite similar to this.

No correct solution

OTHER TIPS

No. Usually you'd handle these sorts of details with your own code.

You may simulate the Raw Numbering done in a ROW_NUMBER() function with code similar to the below format.

CREATE TABLE Temp.Output AS
SELECT *
FROM  (
    SELECT 10 AS ID,'Darren' AS Name
    UNION ALL
    SELECT 20,'Roger'
    UNION ALL
    SELECT 30,'Emil'
    UNION ALL
    SELECT 40,'Doug'
    UNION ALL
    SELECT 50,'Martin'
)
ORDER BY Name ASC
;
SELECT ROWID AS ROWNUMBER, ID, Name
FROM Temp.Output
;
DROP TABLE Temp.Output
;

It will not support "PARTITION BY" for grouping the results (but with some additional SQL you may be able to).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top