Skip to content

Commit e2e4a1c

Browse files
committed
group by must be used for HAVING.
1 parent adc45cf commit e2e4a1c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

12. Having.sql

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
-- GROUP BY HAVING
22
-- it will return all the dept. that has entry more than 2.
33

4-
select Department, count(Department) from Employee group by Department having count(Department) > 2;
4+
select Department, count(Department) from Employee group by Department having count(Department) > 2;
5+
6+
7+
-- difference b/w WHERE & HAVING.
8+
9+
-- 1. WHERE clause is used to filter the rows from table based on specific condition
10+
-- HAVING clause is used to filter the rows from group based on specific condition
11+
12+
-- 2. WHERE is used before GROUPBY clause
13+
-- HAVING is used after GROUPBY clause.
14+
15+
-- 3. WHERE may or may not come with group by
16+
-- HAVING must come with group by only.

0 commit comments

Comments
 (0)