I'm trying to select records with pagination, and I need the total number of records so that I can display the number of records and pages on the UI.
The query I'm using is as below but it always returning the totalcount as 1.
WITH cteEmp AS (SELECT e.empid, e.empname, d.deptid, d.deptname FROM hr.Emp e INNER JOIN hr.dept d ON e.deptid = d.deptid) Select * from (SELECT row_number() over (order by hr.empid desc) rn, Count(*) totalcount, C.empName FROM CTEPO C LEFT JOIN hr.emphistory ON C.empid=hr.empid GROUP BY c.empid,hr.empid) where rn>0 and rn<= 100
CREATE TABLEstatements for a minimal example of your table; theINSERTstatements for some sample data; and your expected output for that sample data.