Where, group by and having clause

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;
What is SQL Server Identifier?
Everything in a SQL server can have an identifier. Be it server, view, trigger, column etc. any database object name is an identifier. Identifiers may or may not be required for all objects.........
What are classes of identifier?
There are two classes of identifier. These identifiers must contain 1 to 128 characters......
What are the Rules for Regular Identifiers
Rules for Regular Identifiers: These rules are dependant on database compatibility level. For a compatibility level 90, following rules may apply.....
Post your comment