Selecting from multiple tables

It is possible to select records from several sources at a time. Consider the following examples. There are two tables each having three rows:

car_portal=> SELECT * FROM car_portal_app.a; a_int | a_text-------+--------     1 | one     2 | two     3 | three(3 rows)car_portal=> SELECT * FROM car_portal_app.b; b_int | b_text-------+--------     2 | two     3 | three     4 | four(3 rows)

When records are selected from both of them, we get the combinations of all their rows:

car_portal=> SELECT * FROM car_portal_app.a, car_portal_app.b; a_int | a_text | b_int | b_text-------+--------+-------+--------     1 | one    |     2 | two     1 | one    |     3 | three     1 | one    |     4 | four     2 | two    |     2 | two     2 | two    |     3 | three     2 | two    |     4 | four     3 | three  |     2 | two 3 | ...

Get Learning PostgreSQL 10 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.