GROUP BY CLAUSE IN SQL

Suraj Gusain
2 min readSep 19, 2022

--

Group by clasue is one of the most important command you will have to learn .

The SQL GROUP BY STATEMENT

The GROUP BY used to group rows from the table. And it has the same values as summary rows. For example, find the number of customers in each country, The GROUP BY is often used with aggregate functions like (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.

GROUP BY Syntax

EXAMPLE:

Query: Find the salary of each employee from Employee table

The SQL HAVING CLAUSE

The HAVING clause is added to SQL because the WHERE keyword can not be used with aggregate functions.

HAVING CLAUSE Syntax

QUERY:

Find the name of the employee whose salary is greater than 4000

SELECT: It is a normal select query that specifies different columns that need to be queried from the given table(s).

GROUP BY: This requires one (or multiple) column names based on which we want the results to be aggregated.

[HAVING condition]: This is an optional condition that could be specified for SELECT queries that use the GROUP BY clause. It’s similar to a WHERE clause in a normal SELECT query.

That’s all for the introduction to GROUP BY CLAUSE ! Keep your eye out for more blogs coming soon that will go into more depth on specific topics.

If you enjoy my work and want to keep up to date with the latest publications or would like to get in touch, I can be found on Medium at SURAJ GUSAIN— Thanks!

Happy Learning:)

--

--