SQL Order By clause is used to short the data in ascending
or descending order on the basis of query result. It does not short the actual
table data but shorts the query result data.
The SQL Order By keyword sorts the records in ascending order by default. To
sort the records in a descending order, you can use the DESC keyword.
SQL - ORDER BY Syntax:
SELECT
column_name, column_name
FROM table_name
ORDER BY column_name ASC|DESC, column_name ASC|DESC;
Parameters
[ORDER BY Order_Item]
Specifies
the item used to sort the final query result set.
[ASC]
Specifies an ascending order for the
query results. ASC is the default order for ORDER BY.
[DESC]
Specifies
a descending order for the query results.
SELECT * FROM [dbo].[Employee]
SELECT * FROM [dbo].[Employee]
ORDER BY ASC By Default Example
The following SQL statement
selects all Employee from the " Employee" table, sorted By Default ASCENDING by
the "First_name" column. If you have not use ASC or ASCENDING in
Query.
SELECT * FROM [dbo].[Employee]
ORDER BY ASC Example
The following SQL statement
selects all Employee from the " Employee" table, sorted ASCENDING by the "First_name"
column.
SELECT * FROM [dbo].[Employee]
ORDER BY DESC Example
The following SQL statement
selects all Employee from the " Employee" table, sorted DESCENDING by the "First_name"
column.
SELECT * FROM [dbo].[Employee]
ORDER BY ASC and DESC in Multiple
Column Example
The following SQL statement
selects all Employee from the " Employee" table, sorted ASCENDING by the "First_name"
column and sorted DESCENDING by the "Department" column.
SELECT * FROM [dbo].[Employee]
ORDER BY First_name ASC, Department DESC;
No comments :
Post a Comment
Ask a Question?