SQL Having Clause - Having Clause in SQL



Demo wikitechydatabase

  • Below is a selection from the wikitechytable table used in the examples:
sql-having-clause-1

HAVING Syntax

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

The SQL HAVING Clause

  • The HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate functions.
SELECT COUNT(id) count, gender FROM wikitechytable GROUP BY gender HAVING gender = 'male'

Output

sql-having-clause-2

Related Searches to SQL Having Clause - Having Clause in SQL