CHAPTER 8. Display Data From Multiple Tables
CHAPTER 8. Display Data From Multiple Tables
Definition
A join is a select statement that retrieves data from two or more tables and connects that
data together to produce a combined set of output.
Tables that share common data elements that support joins are said to be related to each
other.
Types of joins:
1) Equijoins – use the equality operator
2) Non equity joins – do not use the equality operator
3) Inner joins
4) Outer joins
5) Natural joins
6) Cross joins (also known as Cartesian products)
7) Self joins.
Key relationships
- Primary Key
- Foreign Key
Primary key and foreign key relationships help to protect the integrity of data in columns
that are intended to join tables, but their presence is not required in order to create a
successful join.
Entity relationship Diagram (ERD) can be referred in the exam.
It is a diagram that shows the keys and the relationships between two or more tables.
Note
You can join tables without the presence of PRIMARY KEY and FOREIGN KEY constraints.
There is no official connection in the database between key constraints and table joins. Key
constraints are helpful to provide data integrity and to increase odds of successful and
meaningful results from table joins. They are not required.
Inner versus Outer JOINS
3) Inner Joins – connect rows in two or more tables only if there are matched rows in all the
tables that are being joined.
4) Outer Joins – connect rows in two or more tables in a more inclusive way – if data exists
in one table that has no matching value in another, the unmatched rows will be still be
included in the output.
Equijoins versus Non-equijoins
1) Equijoins - connect data in two or more tables by looking for common data among the
tables’ columns.
2) Non-equijons - connect data by looking for relationships that don’t involve equality,
such as “less than” or “greater than” relationships, or situations where data in one table
is within a range of values in another table.
Other joins – 5),6),7) fall into the categories that we have already seen of inner and outer
joins, or equijoins and non-equijoins
3) Inner joins
Example:
PORTS table:
PORT_ID PORT_NAME
---------------------- --------------------
1 Baltimore
2 Charleston
3 Tampa
4 Miami
Next, the SHIPS table: