MySQL Group By and Having Clause

MySQL Group By Clause:

The GROUP BY clause groups the rows in the result table by columns that have the same values, so that each group is reduced to a single row. The GROUP BY column does not have to be in the SELECT clause. Each column is separated by a comma.

MySQL Group By Syntax:

SELECT column_name (s)
FROM table1
WHERE condn
GROUP BY col_name (s)

MySQL Having Clause:

The HAVING clause is very similar to the WHERE clause in that it consists of one or more conditions that define which rows are included in a result set.

MySQL Having Clause Syntax:

SELECT column_name (s)
FROM table1
WHERE condn
GROUP BY col_name (s)
HAVING condn

MySQL Group By and Having Clause Example:

Sample Table:

MySQL New Sample Table
sample city table in mysql

MySQL Group By on Sample Table:

MySQL Group By Code unit

MySQL Having Clause on Sample Table:

MySQL Having Clause Code Unit

MySQL Left Join and Right Join
MySQL Primary Key and Foreign Key
MySQL Aggregate Functions
Procedure-Oriented Programming
Object-Oriented Programming (OOP)
World Wide Web (WWW)
MySQL– Wikipedia

Comments (No)

Leave a Reply