SQL Clauses GroupBy Where Having
SQL Clauses GroupBy Where Having
The GROUP BY clause is used to group rows that have the same values in specified columns into
summary rows,
such as aggregating data (using functions like COUNT, SUM, AVG, etc.) for each group. It is
Example:
FROM employees
GROUP BY department;
2. What is the difference between the WHERE clause and the HAVING clause?
- WHERE clause is used to filter rows before any groupings are made, meaning it is applied to
individual rows.
- HAVING clause is used to filter groups after the GROUP BY clause has been applied, meaning it is
Key Differences:
2. WHERE cannot be used with aggregate functions, whereas HAVING is specifically designed to
FROM employees
GROUP BY department
In this example, the WHERE clause filters out employees with salaries less than 50,000, and the