SQL Order By -Order By in SQL
- By default, The ORDER BY keyword sorts the records in ascending order.
- We use Keyword DESC to sort the data in descending order and the keyword ASC to sort the data in ascending order.
SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC;
SELECT * FROM Employee ORDER BY Country;
The above SQL statement selects all the columns from the "Employee" table, sorted in ascending order by the "Country" column.
- DESC
- ASC
SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... DESC;
SELECT * FROM Employee ORDER BY Country DESC;
The above SQL statement selects all the columns from the "Employee" table, sorted in descending order by the "Country" column.
SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC;
SELECT * FROM Employee ORDER BY Country ASC;
The above SQL statement selects all the columns from the "Employee" table, sorted in ascending order by the "Country" column.
FAQ:
Q: How to use both ASC and DESC commands in the same SQL query.
SELECT * FROM Employee ORDER BY Country ASC, Employee name DESC;
Q: What happens if we do not use ASC and DESC commands.
SELECT * FROM Employee ORDER BY Country, Employee name;
Hope!!! The above tutorial of SQL Order By is helpful for you...
Team,
QA acharya
Tag: SQL order by, Order by in SQL, order by keyword in SQL
![]() |
order by in SQL |
Post a Comment
0 Comments