Tutorials › SQL Tutorial › SQL Quiz

SQL Quiz

10 min read · Lesson 24 of 24

Test what you have learned in this SQL tutorial. Each question has one correct answer. If you get stuck, the SQL Keyword Reference has a summary of every keyword, with links back to the lessons.

Before you start, here is one last warm-up query that pulls together joins, grouping, HAVING, sorting and LIMIT: the top three customers by total value of delivered orders.

Example SQL
SELECT c.name,
       SUM(oi.quantity * p.price) AS delivered_value
FROM customers AS c
JOIN orders      AS o  ON o.customer_id = c.customer_id
JOIN order_items AS oi ON oi.order_id   = o.order_id
JOIN products    AS p  ON p.product_id  = oi.product_id
WHERE o.status = 'delivered'
GROUP BY c.customer_id, c.name
HAVING SUM(oi.quantity * p.price) > 10000
ORDER BY delivered_value DESC
LIMIT 3;
Try it Yourself »

And a second one combining a subquery with CASE: every product with how many units have been ordered and a simple sales label.

Example SQL
SELECT p.name,
       COALESCE((SELECT SUM(oi.quantity) FROM order_items AS oi
                 WHERE oi.product_id = p.product_id), 0) AS units_ordered,
       CASE
         WHEN (SELECT SUM(oi.quantity) FROM order_items AS oi
               WHERE oi.product_id = p.product_id) >= 5 THEN 'Best seller'
         ELSE 'Steady'
       END AS label
FROM products AS p
ORDER BY units_ordered DESC;
Try it Yourself »

If you can read both of these and explain what each line does, you are in good shape. Now for the quiz.

Quiz 15 questions
1. What does SQL stand for?
2. Which statement returns every column from the customers table?
3. Which keyword removes duplicate rows from a result?
4. How do you find customers whose country is missing?
5. Which query lists products from most to least expensive?
6. Which pattern finds names that contain the word "Tech" anywhere?
7. In SQL Server, which keyword is used instead of LIMIT?
8. Is the value 6000 included by the condition price BETWEEN 2000 AND 6000?
9. Which clause filters groups after GROUP BY has been applied?
10. What does COUNT(country) count?
11. Which join returns every customer, even customers with no orders?
12. In AND/OR conditions without brackets, which is evaluated first?
13. What happens if you run UPDATE products SET price = 0; with no WHERE clause?
14. Which constraint stops two rows from having the same value in a column?
15. What does a FOREIGN KEY do?
Tip: Missed a question? Go back to the lesson, open the Try it Yourself editor and experiment with the Skope Shop database until the idea clicks. Practice is the fastest way to learn SQL.
Sign in or create a free account to track progress, earn XP, badges and a certificate.