bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL Joins

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind SQL Joins?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ Orders.OrderID, Customers.CustomerName, Orders.OrderDate
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Here are the different types of JOINs in SQL:
The JOIN clause is used to combine rows from two or more tables, based on a related column between them.
The SQL JOIN Clause

The SQL JOIN Clause

The JOIN clause is used to combine rows from two or more tables, based on a related column between them.

Here are the different types of JOINs in SQL:

  • (INNER) JOIN : Returns only rows that have matching values in both tables
  • LEFT (OUTER) JOIN : Returns all rows from the left table , and only the matched rows from the right table
  • RIGHT (OUTER) JOIN : Returns all rows from the right table , and only the matched rows from the left table
  • FULL (OUTER) JOIN : Returns all rows when there is a match in either the left or right table

Look at an order in "Orders" table:

OrderIDCustomerIDOrderDate
1030821996-09-18

Then, look at a customer in the "Customers" table:

CustomerIDCustomerNameContactNameCountry
2Ana Trujillo Emparedados y heladosAna TrujilloMexico

Here we see that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column.

Then, we can create the following SQL statement (that contains an INNER JOIN ), that selects records that have matching values in both tables:

Example

 SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

and it will produce something like this:

OrderIDCustomerNameOrderDate
10308Ana Trujillo Emparedados y helados1996-09-18
10365Antonio Moreno Taquería1996-11-27
10383Around the Horn1996-11-15
10355Around the Horn1996-12-16
10278Berglunds snabbköp1996-12-16

Previous

SQL Aliases

Next

SQL INNER JOIN