Re-use the SQL queries for listing when counting