Types of Joins
Explore the fundamental SQL joins used to combine rows from two or more tables based on common columns. Learn how inner, outer, left, right, full, cross, and self joins work, with examples to help you understand how to merge related data in relational databases.
We'll cover the following...
Types of Joins
In the previous section we worked with a single table to learn the basics of SQL. However, relational databases define relationships between tables and often queries require gleaning information from two or more tables. Joins allow us to combine rows from multiple tables using columns common between them. In fact, the relations defined amongst tables is what makes relational databases, relational.
To drive the concepts home, we’ll work with two tables that have one column common between them. The two tables are shown below:
Movie Table
| MovieID | MovieName |
|---|---|
| 1 | Star Wars |
| 2 | Sholay |
| 3 | The Italian Job |
Cinema Table
| MovieID | CinemaName | RunForDays |
|---|---|---|
| 2 | Naz Cinema | 101 |
| 5 | Apollo Theater | 45 |
The ANSI SQL standard defines five types of joins that we’ll discuss.
Cross Join
We’ll start with the cross join, which is also known as the cartesian product. In this ...