Final exam
SQL for Beginners
Before you start
- 20 questions, drawn at random from a pool of 34.
- Pass mark: 70%. Your final score is 30% practice + 70% exam.
- No time limit, but finish within 3 hours. You can move between questions before you submit.
- Failed? Review the lessons and try again: every attempt gets a new set of questions.
Question 1 of 20Match the pairs
Match each term to its meaning.
Tap an answer, then tap the place where it belongs (or drag it there).
- Primary key
- Foreign key
- Row
- Column
Question 2 of 20Choose one
What does it mean that SQL is a declarative language?
Question 3 of 20True or false
A primary key column may contain NULL values as long as the non-NULL values are unique.
Question 4 of 20What would you do?
What would you do?
A table named products has columns product_id, name, category and price. You want the names and prices of the 5 most expensive products. Which query is correct?
Question 5 of 20Work it out
A products table has 10 rows with these category values: Toys, Books, Toys, Games, Books, Toys, Music, Games, Books, Toys. How many rows does SELECT DISTINCT category FROM products; return?
Question 6 of 20Choose one
For a page size of 25, which LIMIT and OFFSET return page 4 of the results?
Question 7 of 20What would you do?
What would you do?
A table employees has columns name, department and salary. You want employees in Sales or Marketing who earn more than 60,000. Which WHERE clause is correct?
Question 8 of 20Work it out
A table has prices 5, 10, 15, 20, 25 and 30. How many rows match WHERE price BETWEEN 10 AND 25?
Question 9 of 20Match the pairs
Match each LIKE pattern to a value it matches.
Tap an answer, then tap the place where it belongs (or drag it there).
- 'S%'
- '%ton'
- '_ond%'
- '%ia%'
Question 10 of 20Select all that apply
Which conditions correctly find rows where phone is missing or explicitly test for it? Select all that apply.
Select all that apply.
Question 11 of 20Work it out
A column score has the values 10, 20, NULL and 30. What does AVG(score) return?
Question 12 of 20What would you do?
What would you do?
A CASE expression labels temperatures. It reads: CASE WHEN temp > 20 THEN 'Warm' WHEN temp > 30 THEN 'Hot' ELSE 'Cool' END. What label does a temperature of 35 get, and why?
Question 13 of 20Work it out
A table has 12 rows. Its email column contains NULL in 3 rows. What does SELECT COUNT(email) return?
Question 14 of 20Choose one
Which query finds the highest salary in the employees table?
Question 15 of 20Spot the mistake
This query should count orders per customer for customers with more than 2 orders. Which lines contain errors? Click them.
Question 16 of 20What would you do?
What would you do?
An orders table has these rows (customer_id, total): (1, 50), (2, 30), (1, 20), (3, 80), (2, 40). What does SELECT customer_id, SUM(total) FROM orders GROUP BY customer_id HAVING SUM(total) > 60; return?
Question 17 of 20Put in order
Put these clauses in the order you must write them in a query.
Drag the items, or use the arrow buttons, to put them in order.
- GROUP BY
- SELECT
- WHERE
- ORDER BY
- FROM
- HAVING
Question 18 of 20Choose one
Why does WHERE sale_price < 10 fail when sale_price is an alias defined in SELECT, in most databases?
Question 19 of 20Sort into groups
Should each condition go in WHERE or HAVING?
Tap an item, then tap its group (or drag it there).
Question 20 of 20True or false
Storing a customer's address on every one of their order rows can lead to update anomalies.
Question 21 of 20Choose one
Students can enroll in many courses, and each course has many students. How should this relationship be stored?
Question 22 of 20What would you do?
What would you do?
Table authors has 4 rows. Table books has 7 rows, each with an author_id that matches one of 3 authors; the fourth author has no books. How many rows does authors INNER JOIN books ON matching author_id return?
Question 23 of 20Work it out
Using the same tables (4 authors, 7 books, one author with no books), how many rows does authors LEFT JOIN books return?
Question 24 of 20What would you do?
What would you do?
You want every product along with its total units sold, showing 0 for products never sold. Table products(product_id, name) and table sales(sale_id, product_id, units). Which query is right?
Question 25 of 20Spot the mistake
This query should list all departments, including those with no employees, and each department's number of employees. Which lines contain mistakes? Click them.
Question 26 of 20True or false
Placing a filter on the right table's columns in the WHERE clause of a LEFT JOIN can remove the unmatched left rows, making it behave like an INNER JOIN.
Question 27 of 20Choose one
Which query returns products priced above the average price?
Question 28 of 20Choose one
What is the main benefit of writing a complex query with a CTE (WITH ... AS) instead of nested subqueries?
Question 29 of 20Select all that apply
Which practices protect data quality at the database level? Select all that apply.
Select all that apply.
Question 30 of 20Sort into groups
Choose the better data type for each column.
Tap an item, then tap its group (or drag it there).
Question 31 of 20Choose one
What happens when you run UPDATE products SET price = 0; with no WHERE clause?
Question 32 of 20Put in order
Put the steps of a safe bank transfer transaction in order.
Drag the items, or use the arrow buttons, to put them in order.
- Run both UPDATE statements: subtract the amount from the sender and add it to the receiver
- BEGIN
- COMMIT
- Check that both balances changed as expected
Question 33 of 20True or false
ROLLBACK can undo changes made in the current transaction that have not yet been committed.
Question 34 of 20Choose one