Download ArticleDownload Article

This How.com.vn 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.

  1. How.com.vn English: Step 1 Enter SELECT *.
    This means we'll be looking at all columns. Move to the next line.
  2. How.com.vn English: Step 2 Enter FROM table_name.
    Replace table_name with the name of the table, and then move to the next line.[1]
    Advertisement
  3. How.com.vn English: Step 3 Enter ORDER BY criteria;.
    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. How.com.vn English: Step 4 Execute the command.
    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
      Thanks for submitting a tip for review!

      About This Article

      How.com.vn English: Nicole Levine, MFA
      Written by:
      How.com.vn Technology Writer
      This article was co-authored by How.com.vn staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for How.com.vn. 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 103,558 times.
      How helpful is this?
      Co-authors: 4
      Updated: August 25, 2022
      Views: 103,558
      Categories: Databases | Programming
      Thanks to all authors for creating a page that has been read 103,558 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement