GROUP BY and ORDER BY Clause in SQL
GROUP BY and ORDER BY Clause in SQL
GROUP BY:-
The GROUP BY clause is used to arrange identical data into groups.
The GROUP BY clause is used with the SELECT statement.
The GROUP BY clause is used with aggregate functions like COUNT, MAX, MIN, SUM, and AVG.
SYNTAX:-
SELECT column_Name
FROM table_Name
WHERE condition
GROUP BY column_Name;
EXAMPLE:-
Group By clause
ORDER BY:-
The ORDER BY clause is used to sort the result-set in ascending or descending order.
The ORDER BY clause sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.
SYNTAX:-
Select expressions
FROM tables
[WHERE condition]
ORDER BY expression[asc/desc];
EXAMPLE:-
If you are new to SQL Server start with the following must-watch video: –