Computers & ProgrammingBackend DevelopmentSQL

SQL Order By Keyword

The ORDER BY keyword is used to sort the result-set by one or more specified fields (columns). The ORDER BY keyword sorts the records in ascending order by default. If you want to sort the records in descending order, you can use the DESC keyword.

SQL ORDER BY Syntax

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC | DESC

ORDER BY Example

In this example, we will use the SELECT statement to build a result-set that includes all fields in the Customers table ordering the results by the LastName field.

SELECT *
FROM Customers
ORDER BY LastName
SELECT *
FROM tbl_employees
ORDER BY employeeID

Results

employeeIDemployeeName
1000John Smith
1001Fred White
1002Jane Scott
1003Samuel Williams

Leave a Comment

Your email address will not be published.

Scroll to Top