home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Perl CookbookPerl CookbookSearch this book

14.14. Finding the Number of Rows Returned by a Query

14.14.3. Discussion

The easiest way to find out how many rows a query will return is to use the COUNT function in SQL. For example, take this query:

SELECT id,name FROM People WHERE Age > 30

To find out how many rows it will return, simply issue this query:

SELECT COUNT(*) FROM People WHERE Age > 30

If the database is so volatile that you're afraid the number of rows will change between the COUNT query and the data-fetching query, your best option is to fetch the data and then count rows yourself.

With some DBD modules, execute returns the number of rows affected. This isn't portable and may change in the future.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.