Subqueries - Practice Questions
Subqueries - Practice Questions
Not Graded
Before starting this exercise, load the ‘Artist-Album Database.sql’ file available in Week 11 in
FSB Oracle webserver and execute. This will drop all previously created tables from Artist and
Album database and recreate them.
Write and execute your queries for each of the following request. Try to use subqueries
wherever required.
1. Display the artists’ name and age who have not created any album.
SELECT ARTIST_NAME, ARTIST_AGE
FROM ARTIST
WHERE ARTIST.ARTIST_ID NOT IN
(SELECT ALBUM.ARTIST_ID
FROM ALBUM)
ARTIST_NAME ARTIST_AGE
Bob Marley 66
Black Sabbath
Rush
3. Display the artists’ name and album title whose album price is less than the overall average
album price.
SELECT ARTIST_NAME, ALBUM_TITLE
FROM ARTIST INNER JOIN ALBUM
ON ARTIST.ARTIST_ID = ALBUM.ARTIST_ID
WHERE ALBUM_PRICE < (SELECT AVG(ALBUM_PRICE)
FROM ALBUM);
ARTIST_NAME ALBUM_TITLE
4. Display the artists’ id whose album price is more than the overall average album price. Also,
display the overall average price in the same query.
5. Display the artists’ name and age who have more than one album.
ARTIST_NAME ARTIST_AGE
6. Display the album title and the difference between the album price and the average album
price.
SELECT ALBUM_TITLE, ALBUM_PRICE - (SELECT AVG(ALBUM_PRICE) FROM ALBUM) AS
PRICE_DIFFERENCE
FROM ALBUM;
ALBUM_TITLE PRICE_DIFFERENCE
7. Use DELETE to remove all artists from the ARTIST table who are not in the ALBUM table.
DELETE FROM ARTIST
WHERE ARTIST.ARTIST_ID NOT IN (
SELECT ARTIST_ID
FROM ALBUM);
8. Use DELETE to remove all artist from the ALBUM table whose age is not available.
DELETE FROM ALBUM
WHERE ARTIST_ID IN
(SELECT ARTIST_ID FROM ARTIST WHERE ARTIST_AGE IS NULL);