• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
October 10, 2022 |120 Views
GROUP BY & HAVING clause in MySQL
  Share   Like
Description
Discussion

In this video, we will be discussing in detail what is a Group By & Having Clause in SQL. 

Group By clause is used in the SELECT statement to group the results by one or more columns. The Group By clause is mostly used with aggregate functions such as MAX, SUM, AVG. It is used to group the results of one or more columns. 
Group by clause is also used to collab with SELECT statement in order to arrange data into groups. 

It groups the rows with same data item. It is mostly used with functions like SUM, MAX, AVG, COUNT, etc. 
Syntax of GROUP BY clause: 
SELECT “column_name1”, “function type” (“column_name2”) FROM “table_name” GROUP BY “column_name1” 

HAVING clause is used in the combination with the GROUP BY clause to restrict the groups of returned rows to only those whose the condition is TRUE. HAVING condition is used with WHERE clause in aggregate functions. It is used with the where clause to find otu rows and certain conditions. It is used after GROUP BY clause. 

Syntax of HAVING clause: 
SELECT column_name, aggregate_function (expression) FROM tables [WHERE conditions] GROUP BY column1 HAVING condition;

Group by & having clause: 
https://www.geeksforgeeks.org/difference-between-having-clause-and-group-by-clause/

Read More