Categories
SQL Server Step By Step

SQL Order By Clause

SQL Order By Clause

Hi friends, in this post we will learn about SQL Order By Clause. Order by clause is used to sort the result by one or more columns. By default ORDER BY clause sorts the results in ascending order. To sort the result in descending order you have to use DESC keyword.

Earlier we had discussed about SQL Select Top ClauseLike Clause SQL ServerSQL AND & OR OperatorsSQL Where Clause, Delete Query SQL Server, SQL Update Statement, SQL Select Statement, SQL Insert Statement, Drop Table SQL Server, Rename Table in SQL Server, Create Table SQL Server, Schema In SQL Server, SQL Server Operators, Data Type in SQL Server and Drop-Delete SQL Server Database Using Management Studio or Query.

Table Structure:-

ID NAME AGE ADDRESS SALARY
1 MANN 30 GURGAON 20000
2 JAI 21 Delhi 15000
3 AMAN 33 Kota 12000
4 AMIT 25 Mumbai 6000
5 SURESH 37 Bhopal 8000
6 Komal 22 GURGAON 4000
7 MANN 31 DELHI 22000

SQL Server Query Order By:-

----SELECT DATABASE----
USE HIGHTECHNOLOGY
GO
----ORDER BY CLAUSE EXAMPLES----
----ORDER BY CLAUSE----
SELECT TOP 2 * FROM STUDENT_INFORMATION ORDER BY NAME, PERMADDRESS
GO
----ORDER BY CLAUSE WITH NAME ASCENDING ORDER----
SELECT TOP 2 * FROM STUDENT_INFORMATION ORDER BY NAME ASC
GO
----ORDER BY CLAUSE WITH NAME IN DECENDING ORDER----
SELECT TOP 2 * FROM STUDENT_INFORMATION ORDER BY NAME DESC
GO

SQL Order By Clause