Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте LEFT, RIGHT and INNER JOINs | Об'єднання Таблиць
Розширений Рівень SQL
course content

Зміст курсу

Розширений Рівень SQL

Розширений Рівень SQL

1. Групування
2. Вкладені Запити
3. Об'єднання Таблиць
4. DDL та DML в SQL

book
LEFT, RIGHT and INNER JOINs

The online store has ordered more products from a supplier because they were running low on stock. This means we have some free time until the shipment arrives.

Let's use this opportunity to learn something new! So far, you've been using the standard JOIN in SQL, but there are other types of joins you can use.

Here are the 4 main types of table joins:

  • INNER JOIN: Returns rows with matching values in both tables. This is the same as the standard JOIN you've been using;

  • LEFT JOIN: Returns all rows from the left table and the matching rows from the right table. If there are no matches, it returns NULL for the right table;

  • RIGHT JOIN: Returns all rows from the right table and the matching rows from the left table. If there are no matches, it returns NULL for the left table;

  • FULL JOIN: Returns all rows when there is a match in one of the tables. If there are no matches, it returns NULL for the missing values in the other table.

  • LEFT JOIN: Returns all rows from the left table and the matching rows from the right table. If there are no matches, it returns NULL for the right table;
  • RIGHT JOIN: Returns all rows from the right table and the matching rows from the left table. If there are no matches, it returns NULL for the left table;

Синтаксис для використання цих типів з'єднань насправді простий. Замість звичного JOIN або INNER JOIN просто вкажіть LEFT JOIN або будь-який інший тип JOIN.

У цьому випадку синтаксис буде виглядати так:

Before we dive into using these joins, let's check out the two tables we'll be working with. They contain details about courses and the students enrolled in them.

courses:

enrollments:

The syntax for using these types of joins is actually simple. Instead of the familiar JOIN or INNER JOIN, just specify LEFT JOIN or any other type of JOIN:

Завдання

Swipe to start coding

Write a query to retrieve a list of all courses and the students enrolled, including courses with no registered students.

You need to fetch the following columns in this order:

Use the appropriate type of JOIN to solve this task!

Brief Instructions

  • Retrieve the columns courses.course_id, courses.course_name, courses.description, enrollments.student_name, and enrollments.enrollment_date from the courses table.
  • Use a LEFT JOIN to join the enrollments table.
  • The common column for both tables is courses.course_id = enrollments.course_id.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 5
toggle bottom row

book
LEFT, RIGHT and INNER JOINs

The online store has ordered more products from a supplier because they were running low on stock. This means we have some free time until the shipment arrives.

Let's use this opportunity to learn something new! So far, you've been using the standard JOIN in SQL, but there are other types of joins you can use.

Here are the 4 main types of table joins:

  • INNER JOIN: Returns rows with matching values in both tables. This is the same as the standard JOIN you've been using;

  • LEFT JOIN: Returns all rows from the left table and the matching rows from the right table. If there are no matches, it returns NULL for the right table;

  • RIGHT JOIN: Returns all rows from the right table and the matching rows from the left table. If there are no matches, it returns NULL for the left table;

  • FULL JOIN: Returns all rows when there is a match in one of the tables. If there are no matches, it returns NULL for the missing values in the other table.

  • LEFT JOIN: Returns all rows from the left table and the matching rows from the right table. If there are no matches, it returns NULL for the right table;
  • RIGHT JOIN: Returns all rows from the right table and the matching rows from the left table. If there are no matches, it returns NULL for the left table;

Синтаксис для використання цих типів з'єднань насправді простий. Замість звичного JOIN або INNER JOIN просто вкажіть LEFT JOIN або будь-який інший тип JOIN.

У цьому випадку синтаксис буде виглядати так:

Before we dive into using these joins, let's check out the two tables we'll be working with. They contain details about courses and the students enrolled in them.

courses:

enrollments:

The syntax for using these types of joins is actually simple. Instead of the familiar JOIN or INNER JOIN, just specify LEFT JOIN or any other type of JOIN:

Завдання

Swipe to start coding

Write a query to retrieve a list of all courses and the students enrolled, including courses with no registered students.

You need to fetch the following columns in this order:

Use the appropriate type of JOIN to solve this task!

Brief Instructions

  • Retrieve the columns courses.course_id, courses.course_name, courses.description, enrollments.student_name, and enrollments.enrollment_date from the courses table.
  • Use a LEFT JOIN to join the enrollments table.
  • The common column for both tables is courses.course_id = enrollments.course_id.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 5
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt