Section 8. JOINS


AS Statement

As allows us to rename columns or table selection with an alias



There are several kinds of joins including INNER JOIN, OUTER JOIN and self-join.
This lecture will focus on the INNER JOIN

To get data from both tables, you use the INNER JOIN clause in the SELECT statment as follows:


For each row in the A table, PostgreSQL scans the B table to check if there is any row that matches the condition ie., A.pka = B.fka.

If it finds a match, it combines columns of both rows into one row and add the combined row to the returned result set.

Sometimes A and B tables have the same column name so we have to refer to the column as table_name.column_name to avoid ambiguity.

In case the name of the table is long, you can use a table alias e.g., tbl and refer to the column as tbl.column_name.



Examples of INNER JOIN



댓글 남기기

Close Menu