Order By 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 group and Order By in SQL is is used to sort the data in the ascending or descending order.
Wish to crack SQL job interviews? Intellipaat’s Top SQL Interview Questions are meant only for you!
Order By in SQL
SQL Order By is used to sort the data in the ascending or descending order. It sorts the data in ascending order by default. To sort the data in descending order we use DESC keyword.
Watch this video on Order by Clause in SQL Syntax of Order By in SQL:
SELECT column1, column2….
ORDER BY column1 ASC/DESC, column2 ASC/DESC;
Sort all the students in the ascending order in SQL by the “marks” column.
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 group. The GROUP BY clause follows the WHERE clause and comes before the ORDER BY clause.
Watch this video on Group By Clause in SQL Syntax of Group By in SQL:
SELECT column1, column 2…
GROUP BY column1, column2
ORDER BY column1, column2;
If we want to know the total marks of each student, then GROUP BY is used as follows:
Want to get certified in SQL! Learn SQL from top SQL experts and excel in your career with intellipaat’s SQL certification.
SELECT Name, Sum(marks)
GROUP BY Name;