SELECT..FROM..WHERE..ORDER by

This DML command is used when the data needs to be sorted in some manner. Lets us look at the following table (tbl_employee) including five fields: Social_Security , Last_Name, First_Name, Address and Zip_Code:

Social_Security Last_ Name First_Name Address Zip_Code
476-02-3475 Mitchel John 1223 West Palm Beach Rd 85023
376-76-9083 Spencer Teri 2349 S. 76th Street #102 53219
733-05-3598 James Taylor 23 N. Atlantic Blvd 76215
387-41-1189 Pewinsky Lewis 675 E Indian School Rd 85023
498-32-9089 James Sue 3567 E Tatum Blvd 85032


If you want to sort the information in the table by Zip Codes,  use the following statement:

SELECT * FROM tbl_employee

ORDER BY Zip_Code ASC

The result from the command is

Social_Security Last_ Name First_Name Address Zip_Code
376-76-9083 Spencer Teri 2349 S. 76th Street #102 53219
733-05-3598 James Taylor 23 N. Atlantic Blvd 76215
476-02-3475 Mitchel John 1223 West Palm Beach Rd 85023
387-41-1189 Pewinsky Lewis 675 E Indian School Rd 85023
498-32-9089 James Sue 3567 E Tatum Blvd 85032

Notice how the the field Zip_Code is sorted in ascending order.

ASC: Is used to sort the data in ascending order

DESC: Is used to sort the data in descending order

 

Back to the homepage