Learning Goals
By the end of this section you will:
understand that query results can be used as the basis for further queries.
know how to create subqueries to interrogate data across multiple tables.
All SQL queries return a result in the form of a table, and this result table can be used as the basis for another queryβthis is called a subquery. Subqueries allow you to build more complex logic by using the output of one query as input for another.
The IN OperatorΒΆ
The SQL IN operator is used to check if a value matches any value in a list or the result of a subquery. Go to the W3schools Tutorial on the IN Operator and complete their exercises.
Note that subqueries can be endlessly nested.
Subqueries Activities
Using the Schools database
What are all the percentage results for all the students in grade 7
What the subject name of the subject taught by the teacher in room A2?
What is the name of the subjects where students score over 90%?
List the names of all students who do science.
List the names of the students in grades 4 or 5 who scored over 50% for language.
Repairs database
Who owns devices being repaired by Ted Carrol?
What are the names of the technicians who are still not expert (N) at repairing Macs?
What rate will Byrne be charged for repairs?
List the owners whose devices have a high (H) priority for repair.
What level of qualification has the technician who is doing Jamesβ repair job?