A LEFT JOIN report counts one order for customers who have none. What caused it?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
COUNT(*) counts the NULL-extended customer row produced by the LEFT JOIN. Count a non-nullable order identifier instead to count actual matching orders. Group by a stable customer identifier, and include other selected columns in the grouping as required by the dialect. Additional joins can multiply order rows, so verify cardinality rather than adding DISTINCT without understanding the data. Test customers with zero, one, and several orders. The following query assumes orders.id is non-NULL and each joined row represents one order.
Related Questions in SQL & Relational Databases
What are Clustered and Non-Clustered Indexes in SQL, and when should you use each?
Intermediate level • 443 views
Explain Redis In-Memory Data Structures and Common Caching Patterns (Cache-Aside, Write-Through, Write-Behind).
Intermediate level • 63 views
How do INNER JOIN and LEFT JOIN differ when a customer has no orders?
Easy level • 59 views
Explain SQL ACID properties and the differences between READ COMMITTED and REPEATABLE READ isolation levels.
Intermediate level • 55 views
How would you choose a composite index for a filtered, ordered query?
Medium level • 55 views