Skip to content

SQL foundations: check what you know

Already know some SQL? Answer these 15 questions, about 8 minutes. Each topic you get fully right is marked Known on the SQL roadmap, so you can skip it. Each one you miss is listed for you to study.

Don’t guess. Pick “I don’t know yet” when you’re not sure: a lucky guess would mark a topic Known that you still need to learn.

The 10 topics it checks
  1. Tables, rows and keys
  2. SELECT, WHERE, ORDER BY and LIMIT
  3. DISTINCT
  4. Aggregates
  5. GROUP BY and HAVING
  6. NULL and three-valued logic
  7. Joins: inner, left, right, full, self and cross
  8. Simple subqueries
  9. INSERT, UPDATE and DELETE
  10. Data types and constraints
  1. Question 1 of 15 · Predict the outputorders.customer_id has REFERENCES customers. There is no customer 99. What happens?
    INSERT INTO orders (order_id, customer_id, order_date, status, total)
    VALUES (115, 99, '2026-10-21', 'placed', 10.00);
    
  2. Question 2 of 15 · Predict the outputThe store has 3 electronics products and 2 home ones. Of these 5, only the headphones (59.00) and the desk lamp (24.99) cost more than 20. How many rows?
    SELECT name
    FROM products
    WHERE category = 'electronics' OR category = 'home' AND price > 20;
    
  3. Question 3 of 15 · Predict the outputorders has 14 rows, from 7 customers, with 4 different statuses. How many rows?
    SELECT DISTINCT customer_id, status
    FROM orders;
    
  4. Question 4 of 15 · Predict the outputBen (customer 2) has 4 orders, two of them on 14 October. No one else has more than 3 orders. Which customers does this list?
    SELECT customer_id
    FROM orders
    GROUP BY customer_id
    HAVING count(DISTINCT order_date) >= 4;
    
  5. Question 5 of 15 · Spot the bugThis should list the customers with 2 or more orders. What happens?
    SELECT customer_id, count(*)
    FROM orders
    WHERE count(*) >= 2
    GROUP BY customer_id;
    
  6. Question 6 of 15 · Predict the outputOf the 10 employees, Jon and Zoe have manager 7, and Meera has no manager (NULL). How many rows?
    SELECT name
    FROM employees
    WHERE manager_id <> 7;
    
  7. Question 7 of 15 · Predict the outputevents has 20 rows: 19 from the store’s customers, and a page view from a visitor who wasn’t signed in (customer_id is NULL). Of the 8 customers, only Chen has no events. How many rows?
    SELECT c.name, e.event_id
    FROM customers c
    FULL JOIN events e ON e.customer_id = c.customer_id;
    
  8. Question 8 of 15 · Spot the bugThis should count each customer’s orders. What does it give Dana, who has none?
    SELECT c.name, count(*) AS orders
    FROM customers c
    LEFT JOIN orders o ON o.customer_id = c.customer_id
    GROUP BY c.customer_id, c.name;
    
  9. Question 9 of 15 · Predict the outputOf the store’s 14 orders, only Ben’s 109 and 110 share a customer and a day. How many rows does this self join give?
    SELECT a.order_id, b.order_id
    FROM orders a
    JOIN orders b
      ON b.customer_id = a.customer_id
      AND b.order_date = a.order_date
      AND b.order_id <> a.order_id;
    
  10. Question 10 of 15 · Predict the outputBen (customer 2) has 4 orders. How many times is he listed?
    SELECT name
    FROM customers
    WHERE customer_id IN (SELECT customer_id FROM orders);
    
  11. Question 11 of 15 · Spot the bugThis should list the 6 employees who manage no one. Meera’s manager_id is NULL. How many rows does it give?
    SELECT name
    FROM employees
    WHERE employee_id NOT IN (SELECT manager_id FROM employees);
    
  12. Question 12 of 15 · Predict the outputpayments has 13 rows. What does the last line give?
    BEGIN;
    DELETE FROM payments WHERE payment_id = 13;
    ROLLBACK;
    SELECT count(*) FROM payments;
    
  13. Question 13 of 15 · Predict the outputProduct 9, the phone stand, is already in products at 6.90. What is its price after this?
    INSERT INTO products (product_id, name, category, price)
    VALUES (9, 'Phone stand', 'electronics', 7.50)
    ON CONFLICT (product_id) DO UPDATE SET price = EXCLUDED.price;
    
  14. Question 14 of 15 · Multiple choiceWhich column type keeps a gift card balance exact to the cent?
  15. Question 15 of 15 · Multiple choiceA reviews table has stars integer NOT NULL CHECK (stars BETWEEN 1 AND 5). Which value of stars goes in?

Answered 0 of 15.