8.3. Working with Subselects

Subqueries can be used to obtain search criteria within a SELECT statement. Normally the WHERE clause contains fixed parameters that cannot be modified. In subqueries, the parameters of a WHERE clause can be generated at runtime, which means that the query can stay the same even if the data in your tables changes. In addition, it will help you to reduce the number of queries needed to achieve a certain result.

8.3.1. Why Should You Use Subselects?

To see what you have just learned, we have included a simple example:

phpbook=# CREATE TABLE stock (name text, pday date, price numeric(9,2));
CREATE

You have just created a table containing information about the stock market. Now that the table has been created, it is ...

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.