A join operation is
a query that combines data from two or more tables or views based
usually on relationships among the data in those tables. When multiple
table specifications are listed in the FROM clause of a SELECT statement,
they are processed to form one result set. The result set contains
data from each contributing table and can be saved as a table or used
as is. Most join operations contain at least one join condition, which
is either in the FROM clause or in a WHERE clause.
For example, you can
join the data of two tables based on the values of a column that exists
in both tables. The following query joins the two tables Products
and Sales. FedSQL creates the result set by retrieving the data for
columns Product and Totals where the values match for the column Prodid.
select products.product, sales.totals
from products, sales
where products.prodid=sales.prodid;
Join Result Sets of Tables Products and Sales
Most joins are of two
tables. However, you can join more than two tables. To perform a join
operation of three or more tables, FedSQL first joins two tables based
on the join condition. Then FedSQL joins the results to another table
based on the join condition. This process continues until all tables
are joined into the result set. The following query first joins tables
Products and Sales, which produces a result set, and then joins the
result set and the table Customers, which produces the final result
set.
select products.product, sales.totals, customers.city
from products, sales, customers
where products.prodid=sales.prodid and sales.custid=customers.custid;
Join Result Set of Tables Products, Sales, and Customers
FedSQL supports several
join operations such as simple joins, equijoins, cross joins, qualified
joins, and natural joins. Appropriate syntax determines the type of
join operation. In addition, the qualified and natural join operations
can be affected by specifying the join type, which can be an inner
join or an outer join.
Note: The join operation examples
in this section use the tables Customers, Products, and Sales. To
view the tables,
see Tables Used in Examples.