You are on page 1of 2

The HAVING condition is just another WHERE condition that acts 'secondary constraint' on the result set

The HAVING condition works best when you are trying to apply a restrictive condition after a groupi place.

The HAVING condition is just another WHERE condition that acts 'secondary constraint' on the result set

The HAVING condition works best when you are trying to apply a restrictive condition after a groupi place.
mysql> SELECT * FROM employee -> GROUP BY first_name -> HAVING first_name LIKE '%a%';

Filter with HAVING clause


mysql> -> -> -> -> SELECT Category, COUNT(*) AS Total FROM Topic WHERE Department='Popular' GROUP BY Category HAVING Total<3;

Using Group and Having clause with table join

mysql> CREATE TABLE Employee( -> id int, -> first_name VARCHAR(15), -> last_name VARCHAR(15), -> start_date DATE, -> end_date DATE, -> salary FLOAT(8,2), -> city VARCHAR(10), -> description VARCHAR(15) -> ); Query OK, 0 rows affected (0.02 sec) mysql> mysql> create table job ( -> id int,

-> title -> );

VARCHAR(20)

mysql> SELECT employee.id,COUNT(*) -> FROM employee JOIN job -> GROUP BY employee.id -> HAVING COUNT(*) > 0 -> ORDER BY COUNT(*) desc;

You might also like