-1

So I'm learning SQL at Khan Academy and I can't get my code to work properly to complete the third step of the Playlist maker challenge. I'm supposed to use a nested subquery with an IN operator. I pasted my code below.

The first two sql statements are valid for the steps 1 and 2 of the challenge. The third and fourth statements are my attempts at completing the third step. How do I correct it to complete the challenge?

  1. SELECT title FROM songs WHERE artist = "Queen";

  2. SELECT name FROM artists WHERE genre = 'Pop';

  3. SELECT name FROM artists WHERE genre IN ( SELECT title FROM songs WHERE artist = 'Queen');

  4. SELECT title FROM songs WHERE artist IN ( SELECT name FROM artists WHERE artist LIKE 'Pop');

  • so what is the requirement? Your question should contain everything needed. – Stu Aug 09 '21 at 15:44
  • In `3.` you are attempting to filter a genre column against song titles ... the data probably doesn't match up for that. Similarly, in `4.` your subquery filters on artist, when it probably ought to filter there by genre. – g.d.d.c Aug 09 '21 at 15:45

1 Answers1

0

Guessing a little bit, because you don't provide schema data here, but 3. should probably be:

Select name from artists where genre in (select genre from songs where artist = 'Queen')

Which would return all artists that also have a song in any genre where Queen wrote a song. Similarly, for 4.:

Select title from songs where artist in (select name from artists where genre like 'Pop%')

Ought to give you all song titles for all artists if their genre starts with 'Pop'.

g.d.d.c
  • 46,865
  • 9
  • 101
  • 111