7.6. Aggregating Data

You have seen how individual records can be inserted, updated, and selected. In many cases, it is necessary to perform computations with more than just one record involved.

Aggregation functions can be used. PostgreSQL provides the standard set of aggregation functions that are also provided by most other relational databases. In this section you will learn to use aggregation functions efficiently and you will see how multiple records can be treated.

7.6.1. COUNT

For counting the records in a set of data, SQL provides a function called COUNT. With the help of COUNT, it is an easy task to find out how many records are in a table or how many records satisfy certain conditions.

Take a look at an example:

phpbook=# SELECT COUNT(*) ...

Get PHP and PostgreSQL: Advanced Web Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.