The order by statement allows for table column range. It allows for ascending or descending lists of column values, permitting SQL to reorder your table rows for the purpose of viewing.
Syntax:
SELECT * FROM employees ORDER BY Lastname;
Output:-
Lastname
Firstname
Title
Davis
Julie
manager
Harris
Joel
crew
Hicks
Freddy
crew
Hively
Jessica
crew
Johnson
David
crew
The above example arrange our rows of data alphabetically by lastname.
Ordering by two different columns
First we alphabatize our job titles and again we order by lastname.
Syntax:
SELECT * FROM employees ORDER BY Title,Lastname;
Output:-
Lastname
Firstname
Title
Harris
Joel
crew
Hicks
Freddy
crew
Hively
Jessica
crew
Johnson
David
crew
Davis
Julie
manager
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords sql order by clause, sql server, sql order by desc, sql tutorial