SQL
ORDER By Clause is used to arrange the data either in ascending or descending order.
By default order by clause arrange or sort the data in ascending order.
To sort the records in a descending order.
Syntax:
SELECT expressions
FROM tables
WHERE conditions ORDER BY expression [ASC | DESC];
Example: SELECT * From student ORDER BY branch;
ID | student_name | branch |
---|---|---|
1 | John | CSE |
2 | Peter | ECE |
3 | William | EEE |
The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups.
This GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause.
Syntax
SELECT column1, column2 FROM table_name WHERE [conditions]
GROUP BY column 1, column 2
ORDER BY column1, column2;
GROUP BY column 1, column 2
ORDER BY column1, column2;
Example
SELECT emp_name,salary From employee
WHERE salary>20000GROUP BY emp_name ORDER BY emp_id;
WHERE salary>20000GROUP BY emp_name ORDER BY emp_id;