SQL - Advanced Query PatternsWhat does the SQL function COUNT(*) do when used with GROUP BY?ACounts the number of distinct groupsBCounts the number of rows in each groupCCounts the total rows in the tableDCounts only NULL valuesCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand COUNT(*) functionCOUNT(*) counts all rows, including duplicates and NULLs, in the current context.Step 2: Effect with GROUP BYWhen used with GROUP BY, COUNT(*) returns the number of rows in each group separately.Final Answer:Counts the number of rows in each group -> Option BQuick Check:COUNT(*) with GROUP BY = rows per group [OK]Quick Trick: COUNT(*) counts all rows in each group, including duplicates [OK]Common Mistakes:Thinking COUNT(*) counts distinct groupsAssuming it counts only non-NULL valuesConfusing with COUNT(column_name)
Master "Advanced Query Patterns" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes Advanced Query Patterns - Pivot and unpivot concepts - Quiz 15hard CASE Expressions - CASE in SELECT for computed columns - Quiz 11easy Common Table Expressions (CTEs) - CTE as readable subquery replacement - Quiz 12easy Indexes and Query Performance - CREATE INDEX syntax - Quiz 9hard Indexes and Query Performance - Why indexes matter - Quiz 11easy Indexes and Query Performance - Composite index and column order - Quiz 7medium Transactions and Data Integrity - Deadlock concept and prevention - Quiz 7medium Transactions and Data Integrity - Transaction isolation levels - Quiz 5medium Transactions and Data Integrity - Auto-commit behavior - Quiz 4medium Triggers - Trigger performance considerations - Quiz 5medium