SQL HAVING – SQL Tutorial | Software Testing Material
SQL Having:
While using aggregate functions, we couldn’t use WHERE clause. We need to use SQL HAVING clause while using aggregate functions. The HAVING Clause places conditions on Groups created by the GROUP BY clause where as the WHERE Clause places conditions on the selected columns.
Syntax:
SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) HAVING condition ORDER BY column_name(s);
The HAVING clause must follow the GROUP BY clause in a query. If we use ORDER BY clause in a query then the HAVING clause must precede the ORDER BY clause.
To list out the number of customers in each country and that too the countries with more than 2 customers.
In the next tutorial, we will see How To Use LIKE OPERATOR in SQL
Check out the complete SQL Tutorial by clicking on below link: