close[x]


MySQL

MySQL-Home MySQL-Environment setup MySQL- Workbench MySQL-Basic syntax MySQL-Operator MySQL-Data type MySQL-Comments MySQL-Create DB MySQL-Drop DB MySQL-Select DB MySQL-Create Table MySQL-Drop table MySQL-Truncate MySQL-Primary Key MySQL-Foreign Key MySQL-Null MySQL-Increment MySQL-Having MySQL-Top MySQL-Insert Statement MySQL-Select Statement MySQL-Alter Statement MySQL-Where MySQL-And & Or MySQL-Default values MySQL-Exists MySQL-Order by MySQL-View MySQL-Update Statement MySQL-Delete Statement MySQL-Like MySQL-Sort MySQL-Limit MySQL-Min MySQL-Max MySQL-Group MySQL-In MySQL-Between MySQL-Union MySQL-Count MySQL-Average MySQL-Sum MySQL-Date & Time MySQL-Import MySQL-Export MySQL-Index MySQL-Temporary MySQL-Join MySQL-Full Join MySQL-Inner Join MySQL-Left Join MySQL-Right Join MySQL-Store Procedure MySQL-Injection MySQL-PHP connection



learncodehere.com



MySQL - HAVING

The HAVING Clause enables you to specify conditions that filter which group results appear in the results.

Syntax : HAVING


SELECT column_name(s)
FROM table_name
WHERE condition 
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);

Let's put these statements into real use.

We've a table named Students in our database that contains the following records:

Table : Students

ROLL_NO NAME SUBJECT
1 Will C++
2 SAM Python
3 Rani Node.js
4 Rim Java
5 Micheal JAVA
6 Lara PHP

The following MySQL statement lists the number of Students in each Subject. Only include Subjects with more than 2 Students:

Example : HAVING


SELECT COUNT(ROLL_No), SUBJECT
FROM Students
GROUP BY SUBJECT
HAVING COUNT(ROLL_No) > 1;

Now, after executing the above MySQL statement,

Result

COUNT(ROLL_No) SUBJECT
2 JAVA