M358 - Using joins
fellstrider.com - the logo!
Home| OU Study Rooms | M358 Index | Block 1 - Information Systems | Block 2 - Relational Theory | Block 3 - SQL
 
Using joins

SQL allows for multiple table query processing using the FROM clause. A join is the combination of data from two related columns from two tables.

A join is a refinement of a general combination of data from two tables known as a Cartesian product. The Cartesian product is another table containing all possible combinations of the pairs of rows from the tables.

SELECT *
From s_country, s_city;
Final table of SQL query SELECT *
From s_country, s_city;!

Logical processing is as follows:

Referencing a specific column in one table that has the same identifier as another column from the second table requires the use of dot notation:

s_country.name, s_country.capital, s_city.name, s_city.population

This would be required for the above table in the case of the two name columns. However there is no ambiguity about the population and capital columns. These can be referenced directly.

Relationships

As some of the entries in the columns are identical there is a possibilty of a relationship between the tables. The Cartesian product of the two tables can be used to join the tables based upon the relationship via a join condition.

The join condition is specified in a WHERE clause:

SELECT s_country.name, capital, population
From s_country, s_city
WHERE capital = s_city.name;

Logical processing is as follows:

Final table of SQL query SELECT s_country.name, capital, population
From s_country, s_city
WHERE capital = s_city.name;!

It is helpful if join conditions precede other predicates in any query to help in distinguishing the join.

Home| OU Study Rooms | M358 Index | Block 1 - Information Systems | Block 2 - Relational Theory | Block 3 - SQL
Move on to using aliases and self- joins.

Valid CSS! Valid XHTML 1.0!

Comments, suggestions, ideas to
Stuart Banner