SwitchUp SwitchUp Ranked Best Coding Bootcamps 2025

How to COUNT all rows in SQL query while using LIMIT?

Altcademy Team wrote on 7 February 2018

You can use the OVER() clause in SQL. PostgreSQL has window functions counting rows before LIMIT is applied.
Example:
SELECT count(*) OVER() AS total_count FROM table WHERE condition LIMIT 20

Trusted by

Students and instructors from world-class organizations

Join the upcoming Cohort #111

Enroll for March 2nd, 2026