In this PostgreSQL post explains how to use the PostgreSQL FROM clause with syntax and examples.
The PostgreSQL FROM clause is used to list the tables and any join information required for the query in PostgreSQL.
The syntax for the FROM clause in PostgreSQL is:
The tables used in the PostgreSQL statement. The two tables are joined based on table1.column1 = table2.column1.
It is difficult to explain the syntax for the PostgreSQL FROM clause, so let's look at some examples.
We'll start by looking at how to use the FROM clause with only a single table.
For example:
In this PostgreSQL FROM clause example, we've used the FROM clause to list the table called categories. There are no joins performed since we are only using one table.
Let's look at how to use the FROM clause with two tables and an INNER JOIN.
For example:
This PostgreSQL FROM clause example uses the FROM clause to list two tables - categories and products. And we are using the FROM clause to specify an INNER JOIN between the categories and products tables based on the category_id column in both tables.
Let's look at how to use the FROM clause when we join two tables together using an OUTER JOIN. In this case, we will look at the LEFT OUTER JOIN.
For example:
This PostgreSQL FROM clause example uses the FROM clause to list two tables - categories and products. And we are using the FROM clause to specify a LEFT OUTER JOIN between the categories and products tables based on the category_id columns in both tables.