Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
SQL Inner Join | SQL Joining Tables
Data Manipulation using SQL
course content

Зміст курсу

Data Manipulation using SQL

Data Manipulation using SQL

1. Database and Nested Queries
2. SQL Joining Tables
3. SQL Tasks

bookSQL Inner Join

JOIN operator makes combining the records into two tables based on the related column between them. For example, we want to join singers and songs columns in some way. These tables have the same column: singer_id in songs and id in singers. We join them by this column, and now records are rearranged into groups by this id.

JOIN can be applied for multiple tables, and the syntax is:

12345678
--do not run this query SELECT columns FROM table1 INNER JOIN table2 ON table1.col1 = table2.col2 WHERE conditions GROUP BY columns HAVING agg_condition ORDER BY columns
copy

JOIN is an alternative to nested queries. Let's look at the following example, find all songs released between 1970 and 1990:

123
SELECT songs.title FROM albums INNER JOIN songs ON songs.album_id = albums.id WHERE year>=1970 AND year<=1990
copy

This diagram shows how INNER JOIN works. Chosen columns albums_id and id are joined, and only ids present in both columns appear in the result query. Intersection of sets (1, 2, 3) and (1, 2, 4, 2) is a (1, 2, 2).

This way, we avoid using nested queries. Using Joins is a common practice, and in the next chapters, we'll learn other types, except INNER JOIN.

Завдання
test

Swipe to show code editor

Write the query to find all songs created by AC/DC. Print song's title (title) and singer (naming) to the console.

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

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

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

Секція 2. Розділ 1
toggle bottom row

bookSQL Inner Join

JOIN operator makes combining the records into two tables based on the related column between them. For example, we want to join singers and songs columns in some way. These tables have the same column: singer_id in songs and id in singers. We join them by this column, and now records are rearranged into groups by this id.

JOIN can be applied for multiple tables, and the syntax is:

12345678
--do not run this query SELECT columns FROM table1 INNER JOIN table2 ON table1.col1 = table2.col2 WHERE conditions GROUP BY columns HAVING agg_condition ORDER BY columns
copy

JOIN is an alternative to nested queries. Let's look at the following example, find all songs released between 1970 and 1990:

123
SELECT songs.title FROM albums INNER JOIN songs ON songs.album_id = albums.id WHERE year>=1970 AND year<=1990
copy

This diagram shows how INNER JOIN works. Chosen columns albums_id and id are joined, and only ids present in both columns appear in the result query. Intersection of sets (1, 2, 3) and (1, 2, 4, 2) is a (1, 2, 2).

This way, we avoid using nested queries. Using Joins is a common practice, and in the next chapters, we'll learn other types, except INNER JOIN.

Завдання
test

Swipe to show code editor

Write the query to find all songs created by AC/DC. Print song's title (title) and singer (naming) to the console.

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

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

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

Секція 2. Розділ 1
toggle bottom row

bookSQL Inner Join

JOIN operator makes combining the records into two tables based on the related column between them. For example, we want to join singers and songs columns in some way. These tables have the same column: singer_id in songs and id in singers. We join them by this column, and now records are rearranged into groups by this id.

JOIN can be applied for multiple tables, and the syntax is:

12345678
--do not run this query SELECT columns FROM table1 INNER JOIN table2 ON table1.col1 = table2.col2 WHERE conditions GROUP BY columns HAVING agg_condition ORDER BY columns
copy

JOIN is an alternative to nested queries. Let's look at the following example, find all songs released between 1970 and 1990:

123
SELECT songs.title FROM albums INNER JOIN songs ON songs.album_id = albums.id WHERE year>=1970 AND year<=1990
copy

This diagram shows how INNER JOIN works. Chosen columns albums_id and id are joined, and only ids present in both columns appear in the result query. Intersection of sets (1, 2, 3) and (1, 2, 4, 2) is a (1, 2, 2).

This way, we avoid using nested queries. Using Joins is a common practice, and in the next chapters, we'll learn other types, except INNER JOIN.

Завдання
test

Swipe to show code editor

Write the query to find all songs created by AC/DC. Print song's title (title) and singer (naming) to the console.

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

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

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

JOIN operator makes combining the records into two tables based on the related column between them. For example, we want to join singers and songs columns in some way. These tables have the same column: singer_id in songs and id in singers. We join them by this column, and now records are rearranged into groups by this id.

JOIN can be applied for multiple tables, and the syntax is:

12345678
--do not run this query SELECT columns FROM table1 INNER JOIN table2 ON table1.col1 = table2.col2 WHERE conditions GROUP BY columns HAVING agg_condition ORDER BY columns
copy

JOIN is an alternative to nested queries. Let's look at the following example, find all songs released between 1970 and 1990:

123
SELECT songs.title FROM albums INNER JOIN songs ON songs.album_id = albums.id WHERE year>=1970 AND year<=1990
copy

This diagram shows how INNER JOIN works. Chosen columns albums_id and id are joined, and only ids present in both columns appear in the result query. Intersection of sets (1, 2, 3) and (1, 2, 4, 2) is a (1, 2, 2).

This way, we avoid using nested queries. Using Joins is a common practice, and in the next chapters, we'll learn other types, except INNER JOIN.

Завдання
test

Swipe to show code editor

Write the query to find all songs created by AC/DC. Print song's title (title) and singer (naming) to the console.

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