Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Two Singers | SQL Tasks
Data Manipulation using SQL

book
Challenge: Two Singers

Uppgift

Swipe to start coding

Find the names of the oldest and youngest singers (i. e. singers with oldest and newest releases). Return two records containing the singer's name (naming), his song (title), and release date (year).

Note that some fields can be NULL, excpet year. Thus, you should add WHERE statement to include all albums where the year is not null. Other fields can be NULL.

Print two records in total: first one is for the oldest singer, and the second one is for the youngest singer.

Lösning

(SELECT singers.naming, songs.title, albums.year
FROM songs
FULL OUTER JOIN singers
ON singers.id = songs.singer_id
FULL OUTER JOIN albums
ON albums.id = songs.album_id
WHERE year IS NOT null
ORDER BY year
LIMIT 1)
UNION ALL
(SELECT singers.naming, songs.title, albums.year
FROM songs
FULL OUTER JOIN singers
ON singers.id = songs.singer_id
FULL OUTER JOIN albums
ON albums.id = songs.album_id
WHERE year IS NOT null
ORDER BY year DESC
LIMIT 1)

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 5
single

single

(SELECT _ _ _
FROM _ _ _
_ _ _ singers
ON _ _ _
_ _ _ albums
ON _ _ _
WHERE _ _ _
ORDER BY _ _ _
LIMIT 1)
UNION ALL
(SELECT _ _ _
FROM _ _ _
_ _ _ singers
ON _ _ _
_ _ _ albums
ON _ _ _
WHERE _ _ _
ORDER BY _ _ _
LIMIT 1)
Query ResultQuery Result
No query executed yet...

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

some-alt