I see there are some similar questions, but I was unable to find an answer that I understood as I am not a SQL query expert.
This currently works to get the page of records:
WITH PAGE AS
(
SELECT
ROW_NUMBER() OVER (ORDER BY SEQUENCE_NO ASC) AS _ROW_, *
FROM mytable
)
SELECT *
FROM PAGE
WHERE _ROW_ BETWEEN 0 AND 25
But how can I modify this so that it also returns the total number of records that matched the first query ?
WITH PAGE AS
(
SELECT
ROW_NUMBER(), COUNT(*) OVER (ORDER BY SEQUENCE_NO ASC) AS _ROW_, _TOTAL_, *
FROM mytable
)
SELECT *
FROM PAGE
WHERE _ROW_ BETWEEN 0 AND 25
I get the following error:
Incorrect syntax near 'ROW_NUMBER', expected 'OVER'
OFFSET-FETCHif SQL version is 2012+SEQUENCE_NOunique?