SQL mock tests
Test yourself on the whole course, against the clock: questions from every module, then coding problems you solve and run right here. Your score comes at the end, with every answer explained.
Each mock test has 12 questions drawn from the lessons and up to 3 coding problems, and 45 minutes on the clock, which keeps running if you reload. Questions are worth a point each, and each coding problem 4 points, shared by its tests. Score 60% or more to pass; your best score is kept.
- 01Mock test 112 questions · 3 coding problems · 45 minutes · 24 points
- 02Mock test 212 questions · 3 coding problems · 45 minutes · 24 points
- 03Mock test 312 questions · 3 coding problems · 45 minutes · 24 points
Part A · 12 questions
- What does SELECT DISTINCT do?
- How do you count delivered orders and cancelled orders in one query?
- Which is the standard way to write an alias containing a space?
- What does _ match in a LIKE pattern?
- Which query finds products priced above the average price?
- What makes a self join possible?
- What is the difference between UNION and UNION ALL?
- You insert a customer without giving customer_id, an INTEGER PRIMARY KEY. What happens?
- Which query finds products that cost exactly 59?
- What is the difference between WHERE and HAVING?
- What does INSERT INTO a (x) SELECT y FROM b do?
- Which constraint stops two rows from having the same email?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1Full namesMedium · 4 points
List the full names (first name, a space, last name) of the employees in the
Supportdepartment, as one column.Expected outputRavi Kumar Hana Kim
Loading the editor… - 2Not one orderMedium · 4 points
List the
nameof every customer with no orders, usingNOT EXISTS.Expected outputLucas Martin
Loading the editor… - 3Countries without an aMedium · 4 points
List the
nameof the customers whose country does not contain the lettera(in either case).Expected outputLiam Carter
Loading the editor…
Part A · 12 questions
- What does an INNER JOIN return?
- What does a view store?
- What does ROLLBACK do?
- How do you find customers with no join date?
- What does a LEFT JOIN return?
- Does WHERE price BETWEEN 30 AND 100 include a product priced exactly 100?
- Why does joining a table to itself need table aliases?
- What does LIMIT 5 OFFSET 10 return?
- In orders, customer_id refers to customers.customer_id. What is orders.customer_id called?
- What does COALESCE(phone, email, 'none') return when phone is NULL and email is 'a@b.com'?
- Which pattern matches every name that starts with "Sa"?
- Which clause can use a column alias from SELECT in every database?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1When an alias is requiredHard · 4 points
For the employees in
Support, list each one's first name next to their manager's first name. Both come from the sameemployeestable, so you need two aliases.Expected outputHana | Ravi
Loading the editor… - 2Salary bandsHard · 4 points
Put the employees into salary bands,
under 100k,100k to 150k(100,000 to 150,000 inclusive) andover 150k, and show each band with its number of employees, lowest band first.Expected outputunder 100k | 4 100k to 150k | 3 over 150k | 2
Loading the editor… - 3Orders per statusMedium · 4 points
Show each order
statuswith its number of orders, the most common first (ties in alphabetical order).Expected outputdelivered | 7 processing | 2 shipped | 2 cancelled | 1
Loading the editor…
Part A · 12 questions
- What does SELECT city, COUNT(*) FROM customers GROUP BY city; return?
- After a LEFT JOIN, why count COUNT(o.order_id) instead of COUNT(*)?
- Why do the same-department pairs use a.employee_id < b.employee_id?
- What does CHECK (rating BETWEEN 1 AND 5) do?
- In SQLite, what is 7 / 2?
- What does SUBSTR('CodeMIRAI', 1, 4) return?
- How are dates usually stored in SQLite?
- In PostgreSQL, how do you match a pattern regardless of case?
- How do you find customers with no orders using a LEFT JOIN?
- Why is DECIMAL better than FLOAT for prices?
- Of these clauses, which does the database run first?
- Why prefer NOT EXISTS over NOT IN with a subquery?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1First order, or neverMedium · 4 points
Show every customer's
namewith the date of their first order, ornever, in customer id order.Expected outputAsha Verma | 2024-06-01 Liam Carter | 2024-06-03 Mei Tanaka | 2024-06-12 Carlos Ruiz | 2024-06-28 Fatima Khan | 2024-06-15 Noah Schmidt | 2024-06-18 Sofia Rossi | 2024-07-04 Ethan Brooks | 2024-06-21 Priya Nair | 2024-06-22 Lucas Martin | never
Loading the editor… - 2Keep the duplicatesMedium · 4 points
Count the rows when the countries of customers 1–3 are stacked on those of customers 5 and 9. India appears more than once: keep every row.
Expected output5
Loading the editor… - 3When the database says noHard · 4 points
This insert is refused because
nameisNOT NULL. Fix it so a product calledPen Holderis added (Office, price 15).Expected outputPen Holder | Office | 15
Loading the editor…