I have a SqlServer SELECT
DECLARE @offset INT;
DECLARE @limit INT;
WITH cte
AS (SELECT t.*,
Row_number() OVER (ORDER BY Id) AS RowNum
FROM (SELECT *
FROM Table1
UNION
SELECT *
FROM Table2) t)
SELECT *
FROM cte
WHERE RowNum BETWEEN @offset AND @offset + @limit
How can I know the total of rows limited without the WHERE condition RowNum BETWEEN @offset AND @offset + @limit
You might add count(*) over() to cte: