SQL Left & Right Join
LEFT JOIN returns all records from the left table and matching records from the right table. For records with no matching, it completes the fields with NULL. For example, let's select all albums joined with songs ids with LEFT JOIN:
123SELECT albums.title, songs.id FROM albums LEFT JOIN songs ON songs.album_id = albums.id
On the diagram for this query, we can see that not all albums have songs in a table, so absent fields are autocompleted with NULL. Similarly, we can see in the result query: some albums have empty id's for the songs, because there are no songs for these albums.
Swipe to start coding
Do the joining for tables albums
and songs
using INNER JOIN, RIGHT JOIN, FULL JOIN, and check the difference. Then, find the number of songs for each album (even if there are no songs in it). Think about which JOIN you can use here. Order everything by albums title
.
Рішення
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 5.88
SQL Left & Right Join
Свайпніть щоб показати меню
LEFT JOIN returns all records from the left table and matching records from the right table. For records with no matching, it completes the fields with NULL. For example, let's select all albums joined with songs ids with LEFT JOIN:
123SELECT albums.title, songs.id FROM albums LEFT JOIN songs ON songs.album_id = albums.id
On the diagram for this query, we can see that not all albums have songs in a table, so absent fields are autocompleted with NULL. Similarly, we can see in the result query: some albums have empty id's for the songs, because there are no songs for these albums.
Swipe to start coding
Do the joining for tables albums
and songs
using INNER JOIN, RIGHT JOIN, FULL JOIN, and check the difference. Then, find the number of songs for each album (even if there are no songs in it). Think about which JOIN you can use here. Order everything by albums title
.
Рішення
Дякуємо за ваш відгук!
Awesome!
Completion rate improved to 5.88single