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? The first column of any table A column whose value uniquely identifies each row The password for the database The largest value in a table 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? Every customer's city, including repeats Each different city once The number of cities Only the first city 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: (a = 1 OR b = 2) AND c = 3 a = 1 OR (b = 2 AND c = 3) Left to right with no precedence A syntax error AND binds more tightly than OR. (Chapter 4: AND, OR, NOT, IN, BETWEEN )
5. What is the default sort direction of ORDER BY? Ascending Descending Random Insertion order ASC is the default. (Chapter 5: ORDER BY and LIMIT )
6. What does _ match in a LIKE pattern? Exactly one character Zero or more characters An underscore only A space _ is the single-character wildcard. (Chapter 6: LIKE patterns )
7. If 6 rows exist and 2 have email NULL, what is count(email)? 6 4 2 NULL count(column) counts only non-NULL values. (Chapter 7: NULL values )
8. Which function returns the number of different genres? count(genre) count(DISTINCT genre) sum(genre) distinct(count(genre)) 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? 1 3 10 30 One row per group. (Chapter 9: GROUP BY and HAVING )
10. Why write a.name instead of name in a join? To say which table the column comes from, avoiding ambiguity It is faster name is a reserved word Aliases are required in every query 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(*) count(o.id) sum(o.id) count(c.id) count(column) ignores the NULL produced for unmatched rows. (Chapter 11: LEFT JOIN )
12. What does EXISTS (subquery) check? Whether a table exists Whether the subquery returns at least one row Whether a column is NULL Whether the values are unique EXISTS is true as soon as one row is found. (Chapter 12: Subqueries )
13. Why list the columns in an INSERT? So values match the right columns even if the table changes It is required in SQLite It makes the insert faster To avoid creating a primary key Explicit columns make the statement clear and robust. (Chapter 13: INSERT, UPDATE, DELETE )
14. When is a column's DEFAULT value used? When the INSERT leaves that column out When the INSERT passes NULL Every time a row is updated Only for primary keys An explicit NULL is stored as NULL; defaults fill omitted columns. (Chapter 14: CREATE TABLE and constraints )
Check answers
← Back to the SQL tutorial