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;
commit;
SELECT COUNT(*) FROM my_employees;
commit;
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.

If you are a commercial tool maker and your tool features a great way to handle the issue written about in this FAQ, please check out our advertisement page.



All contents are copyright © 2007-2017 FirebirdFAQ.org unless otherwise stated in the text.


Links   Firebird   News   FlameRobin   Home Inventory powered by FB  
Add content   Advertise   About  

Categories
 Newbies
 SQL
 Installation and setup
 Backup and restore
 Performance
 Security
 Connectivity and API
 HOWTOs
 Errors and error codes
 Miscellaneous