0
0
MySQLquery~5 mins

GROUP BY clause in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the GROUP BY clause do in SQL?
It groups rows that have the same values in specified columns into summary rows, like grouping all sales by each product.
Click to reveal answer
beginner
Which SQL keyword is used to group rows that share the same value in one or more columns?
GROUP BY is used to group rows with the same values in specified columns.
Click to reveal answer
beginner
Why do we often use aggregate functions like SUM() or COUNT() with GROUP BY?
Because GROUP BY creates groups of rows, aggregate functions calculate a summary value (like total or count) for each group.
Click to reveal answer
intermediate
What happens if you use GROUP BY without an aggregate function?
The query will group rows but return one row per group without summarizing data, which might not be useful or can cause errors depending on the SQL mode.
Click to reveal answer
intermediate
Can you use multiple columns in a GROUP BY clause? If yes, what does it do?
Yes, you can group by multiple columns. It groups rows that have the same combination of values in all those columns.
Click to reveal answer
What is the main purpose of the GROUP BY clause in SQL?
ATo sort rows in ascending order
BTo combine rows with the same values into groups
CTo delete duplicate rows
DTo filter rows based on a condition
Which of the following is an aggregate function often used with GROUP BY?
AORDER BY
BWHERE
CJOIN
DSUM()
If you want to group sales data by both region and month, how would you write the GROUP BY clause?
AGROUP BY region, month
BGROUP BY region OR month
CGROUP BY region AND month
DGROUP BY region; GROUP BY month
What will happen if you use GROUP BY but select columns not in the group or aggregate functions?
ASQL will return an error or unpredictable results
BSQL will ignore the extra columns
CSQL will group by those columns automatically
DSQL will delete those columns
Which clause is usually paired with GROUP BY to filter groups after grouping?
ALIMIT
BWHERE
CHAVING
DORDER BY
Explain how the GROUP BY clause works and why it is useful.
Think about how you might group sales by product to find totals.
You got /3 concepts.
    Describe the difference between WHERE and HAVING clauses in relation to GROUP BY.
    Consider when the filtering happens in the query process.
    You got /2 concepts.