ORDER By in SQL and GROUP By Clause in SQL

In this SQL tutorial, we will learn how to use ORDER By and GROUP By in SQL. Group By in SQL is used to arrange similar data into groups and Order By in SQL is used to sort the data in ascending or descending order.

Become a Database Architect

ORDER By in SQL

SQL Order By is used to sort the data in ascending or descending order. It sorts the data in ascending order by default. To sort the data in descending order we use the DESC keyword.

Want to get certified in SQL! Learn SQL from top SQL experts and excel in your career with SQL certification.

Syntax of ORDER By in SQL:

SELECT column1, column2….
FROM table_name
ORDER BY column1 ASC/DESC, column2 ASC/DESC;

Example:
Sort all the students in ascending order in SQL by the “marks” column.

SELECT Name
FROM Student_details
ORDER BY Roll_no ASC;

Still, have queries? Come to Intellipaat’s SQL Community, clarify all your doubts, and excel in your career!

GROUP By in SQL:

It is used to arrange similar data into groups. The GROUP BY clause follows the WHERE clause comes before the ORDER BY clause.

The GROUP BY statement is utilized to group rows with similar values into summary rows, such as finding out the total number of Apples in each store. It is commonly combined with aggregate functions like COUNT(), MAX(), MIN(), SUM(), and AVG() to group the result set based on one or more columns.

Enroll now in SQL course in Bangalore to learn more about SQL concepts.

Syntax of GROUP By in SQL:

SELECT column1, column 2…
FROM table_name
WHERE [condition]
GROUP BY column1, column2
ORDER BY column1, column2;

Example:
If we want to know the total marks of each student, then GROUP BY is used as follows:

SELECT Name, Sum(marks)
FROM Student_details
GROUP BY Name;

Get 100% Hike!

Master Most in Demand Skills Now !

Course Schedule

Name Date Details
SQL Training 23 Mar 2024(Sat-Sun) Weekend Batch
View Details
SQL Training 30 Mar 2024(Sat-Sun) Weekend Batch
View Details
SQL Training 06 Apr 2024(Sat-Sun) Weekend Batch
View Details