You are on page 1of 1

82 Chapter 3: Selecting

These hints may temporarily override the OPTIMIZATION_GOAL and


ISOLATION_LEVEL option settings. For more information about
ISOLATION_LEVEL, see Section 9.7, Blocks and Isolation Levels in Chap-
ter 9, Protecting.
The following sections describe the FROM clause in terms of the different
join operators and special table terms such as derived tables and stored proce-
dure calls. Full details of the <boolean_expression> syntax is left until Section
3.12, Boolean Expressions and the WHERE Clause.

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.

3.4.1 CROSS JOIN


The simplest table expression is a table term, the simplest table term is a table
reference, and the simplest join operator is CROSS JOIN. Here is an example of
a CROSS JOIN between two tables:
CREATE TABLE t1 (
c1 INTEGER NOT NULL );

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

You might also like