Why do we combine several select statements

The clue is in the “Relational” part of “Relational database”

A relation is a set of rows, and can therefore be:

  1. The rows in a table
  2. The rows projected from a view
  3. The rows projected from a query
  4. The rows projected from a common table expression

In theory, all of these are the same, and so selecting from a table is logically the same as selecting from a view, or from another query, and joining two tables is logically the same as joining two queries.

As to why it is done, here are three decent reasons:

  1. To avoid having to save a temporary result set into some structure and then read it out again.
  2. Because in some cases it is not possible to place a condition on a query through a WHERE or HAVING clause, and the predicate must be placed on the result set.
  3. Coding convenience.

Leave a Comment