PDF download Download Article PDF download Download Article

This wikiHow teaches you how to use the ORDER BY clause in SQL to sort results from a table. The ORDER BY clause allows you to sort one or more columns in both ascending and descending order.

Alphabetical Order in SQL

Enter “Select,” then specify the table you want to order with “From [table_name}.” Then, enter “Order by [criteria].” If you don’t specify an order, your data will appear in alphabetical order (or you can enter “ASC”). To pull data in reverse alphabetical order, use “DESC” (for example, “Order by Name Desc”).

  1. This means we'll be looking at all columns. Move to the next line.
  2. Replace table_name with the name of the table, and then move to the next line.[1]
    Advertisement
  3. Here are some examples:
    • For example, if you wanted to display results in alphabetical order based on a column called NAME, you'd use ORDER BY NAME;. Ascending order is the default sort order, but you could also specify that you want it ascending using ORDER BY NAME ASC; if you'd like.
    • If you'd rather show the results in the opposite order, you'd use ORDER BY NAME DESC;. DESC means "descending order."
    • If you want to sort based on two columns, separate them by commas. For example, ORDER BY LAST_NAME ASC, FIRST_NAME DESC; would display results sorted alphabetically by last name. If the same LAST_NAME matches multiple FIRST_NAME entries, the results of FIRST_NAME will also display in descending order.
  4. You will now see your SQL results in the appropriate order.
  5. Advertisement

Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Tips

Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!

You Might Also Like

Use Microsoft AccessThe Ultimate Guide to Using Microsoft Access
Learn Data EntryLearn Data Entry
Make a Database Using MS AccessMake a Database Using MS Access
Reset SA Password in SQL ServerReset SA Password in SQL Server
Import Web Data Into Excel on PC or Mac2 Ways to Import Data from the Web into Excel: Windows & Mac
Add Data to a Pivot TableAdd Data to a Pivot Table
Make an Inventory Database in Access Make an Inventory Database in Access: Complete Guide
Delete Duplicate Records in OracleEverything You Need to Know About Removing Duplicate Records in Oracle
Link Tables in AccessLink Tables in Access
Create a Database from an Excel SpreadsheetCreate a Database from an Excel Spreadsheet
Download Microsoft AccessDownload Microsoft Access
Hack a DatabaseHack a Database
Write Basic SQL Statements in SQL ServerWrite Basic SQL Statements in SQL Server
Check the Query Performance in an SQL Server Check SQL Server Query Performance: Step-by-Step Guide
Advertisement

About This Article

Nicole Levine, MFA
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. This article has been viewed 113,007 times.
How helpful is this?
Co-authors: 4
Updated: August 19, 2024
Views: 113,007
Categories: Databases | Programming
Thanks to all authors for creating a page that has been read 113,007 times.

Is this article up to date?

Advertisement