Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
SQL ORDER BY Clause

SQL ORDER BY Clause: Sorting Data in a Structured Manner

Posted on February 8, 2025February 8, 2025 By Rishabh saini No Comments on SQL ORDER BY Clause: Sorting Data in a Structured Manner

SQL ORDER BY Clause

Introduction

When working with databases, retrieving data in a meaningful order is crucial for readability and analysis. To assist us in sorting records according to particular table columns, SQL offers the ORDER BY clause. This clause allows us to arrange data in either ascending (ASC) or descending (DESC) order.

In this blog post, we will explore the ORDER BY clause in SQL, understand its syntax, and see real-world examples using MySQL.

Complete Python Course with Advance topics:-Click Here
SQL Tutorial :-Click Here

Syntax of ORDER BY Clause

Sorting in Ascending Order

SELECT ColumnName1, ..., ColumnNameN FROM TableName ORDER BY ColumnName ASC;

Sorting in Descending Order

SELECT ColumnName1, ..., ColumnNameN FROM TableName ORDER BY ColumnName DESC;

Default Sorting (Ascending Order)

SELECT ColumnName1, ..., ColumnNameN FROM TableName ORDER BY ColumnName;

Note: If no keyword (ASC or DESC) is specified, SQL sorts the data in ascending order by default.

Example Scenarios

Let’s look at a table of customers that contains the following information:

IDNameAgeAddressSalary
1Raj Verma28Delhi50000
2Simran Kaur25Chandigarh48000
3Amit Singh30Lucknow55000
4Pooja Rao27Hyderabad52000
5Aditya Joshi29Pune53000
6Meera Sharma26Jaipur49000
7Vikram Das31Kolkata60000
8Anjali Nair24Bangalore47000
9Suresh Patil32Mumbai58000
10Rohan Iyer35Chennai62000

Example 1: Sorting in Ascending Order by Customer Name

Query:

SELECT * FROM customers ORDER BY Name ASC;

Output:

IDNameAgeAddressSalary
9Aakash Yadav32Mumbai43500
3Amit Singh45Meerut65000
5Balwant Singh45Varanasi36000
1Raj Verma21Delhi22000
6Meera Sharma26Mathura22000
8Anjali Nair29Pune40000
4Pooja Rao36Azamgarh26000
7Vikram Das19Ahmedabad38000
10Rohan Iyer35Aurangabad68800
2Simran Kaur22Bhopal21000

Example 2: Address Sorting in Ascending Order

Query:

SELECT * FROM customers ORDER BY Address;

Output:

IDNameAgeAddressSalary
7Rohit Shrivastav19Ahmedabad38000
10Sahil Sheikh35Aurangabad68800
4Ritesh Yadav36Azamgarh26000
2Shiva Tiwari22Bhopal21000
6Mahesh Sharma26Mathura22000
3Ajeet Bhargav45Meerut65000
1Himani Gupta21Modinagar22000
9Aakash Yadav32Mumbai43500
8Neeru Sharma29Pune40000
5Balwant Singh45Varanasi36000

Example 3: Salary Sorting in Declining Order

Query:

SELECT * FROM customers ORDER BY Salary DESC;

Output:

IDNameAgeAddressSalary
10Sahil Sheikh35Aurangabad68800
3Ajeet Bhargav45Meerut65000
9Aakash Yadav32Mumbai43500
8Neeru Sharma29Pune40000
7Rohit Shrivastav19Ahmedabad38000
5Balwant Singh45Varanasi36000
4Ritesh Yadav36Azamgarh26000
6Mahesh Sharma26Mathura22000
1Himani Gupta21Modinagar22000
2Shiva Tiwari22Bhopal21000

Conclusion

The ORDER BY clause in SQL is a powerful tool that enables database users to organize data effectively. Whether sorting alphabetically, numerically, or chronologically, this clause enhances data retrieval and usability.

  • Use ASC for ascending order.
  • Use DESC for descending order.
  • Omitting the sorting keyword defaults to ascending order.

Mastering the ORDER BY clause will help you manage and analyze database records efficiently, improving data presentation and decision-making.

Download New Real Time Projects :-Click here
Complete Advance AI topics:- CLICK HERE


sql order by clause
sql order by clause is invalid in views
sql order by clause is used for
sql group by clause
sql group by clause with case statement
sql group by clause multiple columns
sql server order by clause
sql query order by clause
sql order by desc limit 1
sql order by desc null last
sql order by clause example
group by clause in sql
sql order by clause
how does the sql order by clause work
what does the sql order by clause 2
sql order by clause is invalid in views

Post Views: 516
SQL Tutorial Tags:clause, clause commands, clauses in sql, clauses mysql, group by clause, group by clause in sql, oracle sql order by clause, order by clause, order by clause in sql, order by clause in sql ascending, order by clause queries, sql group by clause, sql order by clause, sql order by clause examples, sql order by clause with example, sql top clause, top clause in sql, top clause syntax, use order by with where clause in sql, what is order by clause

Post navigation

Previous Post: How to Sort a Dictionary in Python
Next Post: Strong Number in Python

More Related Articles

SQL DROP TABLE Command Understanding SQL DROP TABLE Command: A Comprehensive Guide SQL Tutorial
SQL ALTER TABLE SQL ALTER TABLE: A Comprehensive Guide SQL Tutorial
UNIQUE Key in SQL Understanding UNIQUE Key in SQL with Examples SQL Tutorial

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. Understanding the SQL DELETE Statement and Its Variants
  2. SQL Temporary Tables: A Handy Tool for Developers
  3. SQL SELECT TOP Clause: A Comprehensive Guide
  4. SQL UPDATE with JOIN
  5. Understanding SQL CROSS JOIN with Examples
  6. IN vs EXISTS in SQL: A Complete Guide

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,612)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,209)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,861)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme