Professional Documents
Culture Documents
3.4 JOIN
There are five different operators involving the JOIN keyword, discussed in the
next five sections:
n CROSS JOIN to create a Cartesian product of two tables.
n INNER JOIN to select matching combinations of rows from two tables.
n LEFT OUTER JOIN to include all the rows from the left-hand table in
addition to the matching combinations of rows from both tables.
n RIGHT OUTER JOIN to include all the rows from the right-hand table.
n FULL OUTER JOIN to include all the rows from both tables.
CREATE TABLE t2 (
c1 INTEGER NOT NULL,
c2 INTEGER NOT NULL );
INSERT t1 VALUES ( 1 );
INSERT t1 VALUES ( 2 );
INSERT t2 VALUES ( 1, 7 );
INSERT t2 VALUES ( 1, 8 );
INSERT t2 VALUES ( 1, 9 );
SELECT t1.c1,
t2.c1,
t2.c2
FROM t1 CROSS JOIN t2
ORDER BY t1.c1,
t2.c1,
t2.c2;
A join is a operation on two tables, to combine or join rows from each table to
create rows in a single result set. This result set is sometimes called a virtual
table, and it contains (logically speaking) all the columns from both tables.
Different join operators combine rows in different ways. In particular, the
CROSS JOIN operator combines every row in one table with every row in the
other table; in other words, it produces every combination of rows in the two