MySQL interview questions
BetaInnoDB, indexing, EXPLAIN, isolation levels and MySQL specifics.
Subtopics
- Joins8
- Aggregates & GROUP BY/HAVING8
- Window functions8
- CTEs8
- Indexes & seeks vs scans6
- Execution plans6
- Transactions & isolation levels6
- Deadlocks6
- Normalization6
- Stored procedures6
- NULL semantics6
- Query tuning6
Sample questions
- CodingJuniorAggregates & GROUP BY/HAVING
Table
orders(id, customer_id, amount).amountcan be NULL when the price has not been settled yet. For every customer that appears in the table return the number of orders they placed and the sum of their known amounts. An order with a NULL amount - CodingJuniorAggregates & GROUP BY/HAVING
Table
reviews(id, product_id, rating)whereratingis an integer from 1 to 5. Return the products that have at least 3 reviews and an average rating of 4 or higher. Columns:product_id,review_count,avg_rating(the average rounded to 2 decimal places). - TheoryJuniorAggregates & GROUP BY/HAVING
What is the difference between
WHEREandHAVINGin a query that usesGROUP BY? - TheoryJuniorAggregates & GROUP BY/HAVING
MySQL runs with
ONLY_FULL_GROUP_BYenabled by default (the default since MySQL 5.7). What does this mode require of a query that usesGROUP BY, and what error do you get if you violate it? - CodingJuniorCTEs
Tables
customers(id, name)andorders(id, customer_id, amount). Using a CTE for the per-customer totals, return the customers whose total order amount is strictly above the average of the per-customer totals. Customers with no orders take no part in the average and are never - TheoryJuniorCTEs
What is a Common Table Expression (
WITH ... AS (...)), and what readability problem does it solve compared to nesting subqueries?