Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1WHERE points > (SELECT AVG(points) FROM students) | AThe sub-select can return many productId values, but = only compares with one value. IN should be used to match a list. | |
| 2WHERE studentId IN (SELECT studentId FROM orders) | BKeeps only the rows whose points are above the average, which the inner query works out first | |
| 3A sub-select that returns a single value can be used after = to find the rows that match it, such as the highest price | CSELECT name FROM products WHERE productId IN (SELECT productId FROM orders); | |
| 4When a sub-select returns a list of values, use IN so the outer query matches any value in that list | DKeeps only the students whose ID appears in the list of IDs the inner query returns from orders | |
| 5SELECT firstName FROM students WHERE points > SELECT AVG(points) FROM students; | EThe sub-select is missing its brackets. A sub-select must be wrapped in ( ) so the database knows where the inner query starts and ends. | |
| 6SELECT name FROM products WHERE productId = (SELECT productId FROM orders); | FSELECT name FROM products WHERE price = (SELECT MAX(price) FROM products); |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
(SELECT ...) — A sub-select is a SELECT inside brackets in a WHERE clause. It runs first and its result is used by the outer query, e.g. to compare with an AVG or to match values using IN.SELECT firstName FROM students
WHERE points > (SELECT AVG(points)
FROM students);SELECT name FROM products
WHERE productId IN (SELECT productId
FROM orders);SELECT firstName, points FROM students
WHERE points = (SELECT MAX(points)
FROM students);SELECT name FROM products
WHERE price > (SELECT AVG(price)
FROM products);SELECT firstName FROM students
WHERE studentId IN (SELECT studentId
FROM results WHERE mark > 90);