Sitemap
SQL Explained

SQL Explained is your go-to publication for mastering SQL, from basics to advanced queries. Learn best practices, optimizations, and real-world applications through clear, concise, and practical insights. Perfect for beginners and experts alike! 🚀 #SQL #Data

Member-only story

Intermediate SQL Topics-Part 2

8 min readApr 17, 2025

--

Press enter or click to view image in full size
Photo by Providence Doucet on Unsplash

SQL GROUP BY?

GROUP BY is used in combination with aggregate functions like SUM(), COUNT(), AVG(), MIN(), and MAX() to group rows with the same values in specified columns into summary rows.

🧠 Syntax:

SELECT
column1,
column2,
aggregate_function (column3)
FROM
table_name
GROUP BY
column1,
column2;

The GROUP BY is an optional clause of the SELECT statement. The GROUP BY clause allows you to group rows based on values of one or more columns. It returns one row for each group.

Press enter or click to view image in full size

The table on the left side has two columns id and fruit. When you apply the GROUP BY clause to the fruit column, it returns the result set that includes unique values from the fruit column:

SELECT
fruit
FROM
sample_table
GROUP BY
fruit;

In practice, you often use the GROUP BY clause with an aggregate function such as MIN, MAX, AVG, SUM, or COUNT to calculate a measure that provides the information for each group.

--

--

Shaloo Mathew
Shaloo Mathew

Written by Shaloo Mathew

I love working with data and finding the stories it tells. Through analytics and technology, I aim to turn data into useful insights.

SQL Explained
SQL Explained

Published in SQL Explained

SQL Explained is your go-to publication for mastering SQL, from basics to advanced queries. Learn best practices, optimizations, and real-world applications through clear, concise, and practical insights. Perfect for beginners and experts alike! 🚀 #SQL #Data