FAQ: Subqueries - Comparison Operators

This community-built FAQ covers the "Comparison Operators " exercise from the lesson “Subqueries”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Analyze Data with SQL

FAQs on the exercise _Comparison Operators _

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Did anyone else begin this section of the lesson only to find that the answer was already filled in?

Why is this valid

SELECT *

FROM drama_students

WHERE grade = (SELECT grade from band_students WHERE id = 20);

But this doesn’t return any result

SELECT *

FROM drama_students

WHERE grade = (SELECT grade from drama_students WHERE id = 20);
2 Likes

This initially confused me, too.

For the purpose of this exercise, Emlynne is not yet enrolled in drama, so her id ( id = 20) is not listed in the drama_students table.

1 Like

How come we can’t simply use this SELECT * FROM drama_students WHERE grade = 10; ??

I been asking myself the same question. its more straightforward in this manner.

You can, but it’s a simplified question. The point of the subquery here is that you’re filtering from something located in another table. Think of it like, instead of WHERE grade = 10 it’s WHERE grade = Emlynne Torritti grade from band_students

This actually explained for me why they were providing what I thought was superfluous information; I didn’t understand what her dropping band and joining drama had to do with the query since the code didn’t actually do this.