How to get record count for any query without executing it?

Sometimes you just want to see how many records would some query produce, without actually fetching them all. With Firebird 2 and derived tables it's quite easy:

SELECT COUNT(*) FROM ( your select query );

For example:

SELECT COUNT(*) FROM ( select * from employee where emp_no > 8 );

In earlier versions (1.x) of Firebird you should either rewrite the query to get the record count, or create a view and do SELECT COUNT(*) from it. For example:

create view my_employees as select * from employee where emp_no > 8;
SELECT COUNT(*) FROM my_employees;
drop view my_employees;

Do you find this FAQ incorrect or incomplete? Please e-mail us what needs to be changed. To ensure quality, each change is checked by our editors (and often tested on live Firebird databases), before it enters the main FAQ database. If you desire so, the changes will be credited to your name. To learn more, visit our add content page.

All contents are copyright © 2007-2023 unless otherwise stated in the text.

Links   Firebird   News   FlameRobin   Powered by FB: Home Inventory   Euchre  
Add content   About  

 Installation and setup
 Backup and restore
 Connectivity and API
 Errors and error codes