Describe where, group by and having clause with examples for each of them.
WHERE: Where clause in a SELECT query is used to retrieve specific records that meet the specified criteria.
SYNTAX:SELECT column_name FROM Table_name WHERE predicate
Example: to display customers with first name is john
Select first_name From customer Where first_name =’john’;
GROUP BY: Group By clause in select statement is used to group or collect data of multiple records of one ore more columns.
SYNTAX: SELECT column_name FROM table_name WHERE predicate GROUP BY column1, column2..;
Example: To Group records by city
SELECT city_name FROM Customer GROUP BY city;
HAVING: The HAVING clause is used to filter records that have been grouped using GROUP BY clause. Hence HAVING clause is used with GROUP BY.
Syntax: SELECT column_name FROM table_name WHERE predicates GROUP BY column1,.. HAVING condition1…
Example: To Group records by employee with salary > 10000
SELECT emp_name FROM employee GROUP BY emp_name HAVING salary > 1000;