TetSharing

SQL final quiz

One question from each of the 14 chapters. Pick an answer for each, then press Check answers. Each explanation links back to the chapter it comes from, so you know exactly what to reread.

14 questions

1. What is a primary key?

A primary key such as id gives every row a unique identity. (Chapter 1: Get started)

2. What does SELECT DISTINCT city FROM customers; return?

DISTINCT removes duplicate rows from the result. (Chapter 2: SELECT columns)

3. Which operator means "not equal" in standard SQL?

<> is standard; SQLite also accepts !=. (Chapter 3: WHERE filters)

4. WHERE a = 1 OR b = 2 AND c = 3 is evaluated as:

AND binds more tightly than OR. (Chapter 4: AND, OR, NOT, IN, BETWEEN)

5. What is the default sort direction of ORDER BY?

ASC is the default. (Chapter 5: ORDER BY and LIMIT)

6. What does _ match in a LIKE pattern?

_ is the single-character wildcard. (Chapter 6: LIKE patterns)

7. If 6 rows exist and 2 have email NULL, what is count(email)?

count(column) counts only non-NULL values. (Chapter 7: NULL values)

8. Which function returns the number of different genres?

DISTINCT inside count counts unique non-NULL values. (Chapter 8: COUNT, SUM, AVG, MIN, MAX)

9. SELECT genre, count(*) FROM books GROUP BY genre; returns how many rows for our 3 genres?

One row per group. (Chapter 9: GROUP BY and HAVING)

10. Why write a.name instead of name in a join?

When both tables have a name column, the prefix is required. (Chapter 10: INNER JOIN)

11. Which expression counts orders per customer and gives 0 for customers without orders?

count(column) ignores the NULL produced for unmatched rows. (Chapter 11: LEFT JOIN)

12. What does EXISTS (subquery) check?

EXISTS is true as soon as one row is found. (Chapter 12: Subqueries)

13. Why list the columns in an INSERT?

Explicit columns make the statement clear and robust. (Chapter 13: INSERT, UPDATE, DELETE)

14. When is a column's DEFAULT value used?

An explicit NULL is stored as NULL; defaults fill omitted columns. (Chapter 14: CREATE TABLE and constraints)

← Back to the SQL tutorial