Collection Contents Index Displaying a list of tables Restricting a join pdf/chap13.pdf

First Guide to SQL Anywhere Studio
   PART 3. Basic SQL
     CHAPTER 13. Joining Tables       

Joining tables with the cross product


One of the tables in the sample database is sales_order, which lists the orders placed to the company. Each order has a sales_rep column, containing the employee ID of the sales representative responsible for the order. There are 648 rows in the sales_order table.

You can get information from two tables at the same time by listing both tables in the FROM clause of a SELECT query.

Example 

The following example lists all the data in the employee table and the sales_order table:

SELECT *
FROM sales_order CROSS JOIN employee

The results of this query, displayed in the Interactive SQL data window, match every row in the employee table with every row in the sales_order table. Since there are 75 rows in the employee table and 648 rows in the sales_order table, there are 75 ( 648 = 48,600 rows in the result of the join. Each row consists of all columns from the sales_order table followed by all columns from the employee table. This join is called a full cross product.

The cross product join is a simple starting point for understanding joins, but not very useful in itself.


Collection Contents Index Displaying a list of tables Restricting a join pdf/chap13.pdf