my question is similar to this one: Need a row count after SELECT statement: what's the optimal SQL approach?
But I want to get the total of rows from a query, and then use limit to create pagination so I can't use the returned rows. From a simple query:
select * from res_groups
I got into this:
select a.*, (select count(1) from (select * from res_groups) e) total
from (select * from res_groups) a limit 10 offset 10;
Or I could use the easy approach and make two queries:
select * from res_groups limit 10;
select count(*) from res_groups;
Will the first query be performatic? I'm afraid that the query from res_groups will be executed twice?
Is there any other way? ps: I'm using postgres, I know that mysql has FOUND_ROWS()