SQLforGeeks
  • Home
  • SQL
  • SQL Tutorial
  • SQL Syntax
  • Our Services
Contact
  1. SQL
  2. ORDER BY clause

Text copied!

« Previous
Next »

ORDER BY clause

May 12, 2023, 7:42 a.m. under SQL

  • Hi! You should check HAVING clause post first.

    SQL clause is the specific part of a SQL statement which is used to perform various operations. It can be combined to create more complex queries to retrieve and manipulate data.

    ORDER BY clause :

    ORDER BY clause is used to sort the data in ascending or descending order based on column(s). It is often used with other clauses such as 'SELECT', 'FROM', 'HAVING' and 'ORDER BY' etc. to retrieve, specify table, filter, sort and manipulate data.

    The syntax of the ORDER BY clause generally looks like this :
    SELECT column_name(s)
    FROM table_name
    ORDER BY column_name(s) ASC;
            

    • Specify the column(s) name after the 'SELECT' keyword.

    • Specify Asterisk (*) symbol to selects all columns from the table after the 'SELECT' keyword.

    • Specify the table name after the 'FROM' keyword.

    • Specify the column(s) name and sorting order after the 'ORDER BY' keyword. 'ASC' stands for ascending order and 'DESC' stands for descending order. if you don't mention the sorting order, 'ASC' is default.

    Here's an example of how you might use the ORDER BY clause :

    1. Let's assume we have a table named "[Employees]".

    ORDER BY clause

    2. Let's assume you want to retrieve the employees salary from highest to lowest in the [Employees] table.

    3. Run below SQL statement :

    SELECT *
    FROM [Employees]
    ORDER BY Salary DESC;
            

    4. Above statement will sort each rows in descending order based on the salary column from the [Employees] table.

    ORDER BY clause

    That's it! You have successfully sorted the data in descending order from [Employees] table.

    Frequently Asked Questions :

    What is ORDER BY clause?

    The ORDER BY clause sorts the result set of a SQL query based on specified columns.

    Can I have 2 ORDER BY clauses in SQL?

    No, SQL does not support having two ORDER BY clauses in a single query.

    How to write ORDER BY with WHERE clause in SQL?

    To write ORDER BY with WHERE clause in SQL, simply include both clauses in your query, like: SELECT * FROM table_name WHERE condition ORDER BY column_name.

    What is ORDER BY condition in SQL?

    ORDER BY condition in SQL specifies the criteria for sorting the result set, typically used with the SELECT statement.
    Thank You! You should check JOIN clause post next.
    « Previous
    Next »
    RELATED :

    What is SQL

    What is T-SQL

    Difference between DBMS and Data Warehouse

    Download SQL Server

    Install SQL Server

    Download SQL Server Management Studio SSMS

    SQL Server Management Studio

    SQL Database

    Download database

    Restore database

    Backup database

    Attach database

    Detach database

    Create database

    Delete database

    Rename database

    Select database

    Database offline

    Database online

    SQL Commands

    SQL Tables

    Create table

    Truncate table

    Delete table

    Rename table

    Select table

    Alter table

    SQL Data Types

    SQL Comments

    SQL Constraints

    SQL Joins

    SQL inner join

    SQL left join

    SQL right join

    SQL full join

    SQL cross join

    SQL self join

    INSERT INTO SELECT statement

    INSERT INTO statement

    SQL Clauses

    SELECT clause

    FROM clause

    WHERE clause

    GROUP BY clause

    HAVING clause

    JOIN clause

    UNION clause

    UNION ALL clause

    TOP clause

    DISTINCT clause

    SQL Operators

    SQL Arithmetic operators

    SQL Comparison operators

    SQL Logical operators

    UNION operator

    UNION ALL operator

    INTERSECT operator

    EXCEPT operator

    LIKE operator

    NOT LIKE operator

    IN operator

    NOT IN operator

    IS NULL operator

    IS NOT NULL operator

    EXISTS operator

    NOT EXISTS operator

    BETWEEN operator

    NOT BETWEEN operator

    SQL Functions

    SQL Built-In functions

    CHARINDEX function

    DATEADD function

    CONCAT function

    LEN function

    REPLACE function

    SUBSTRING function

    CASE statement

    GETDATE function

    DATEPART function

    DATEDIFF function

    CAST function

    TRY_CAST function

    CONVERT function

    TRY_CONVERT function

    ISNULL function

    NULLIF function

    COALESCE function

    SQL Window functions

    ROW_NUMBER function

    RANK function

    DENSE_RANK function

    IIF function

    CHOOSE function

    SQL Store Procedure

    Store Procedure vs. Function

    SQL Subquery

    SQL Aliases

    Temp table

    SQL Error Handling

    SQL Variables

    SQL Views

    SQL Merge

    SQL CTE

    SQL WITH TIES

    Define Transaction in DBMS

    ACID properties in DBMS

    Types of Triggers in DBMS


    • Have Some Questions?
    logo

    Elevate your data experience with SQL excellence

    Quick Links
    •  Home
    •  SQL Tutorial
    •  SQL Syntax
    •  Our Services
    Our Services
    • Web Development
    • BI Development
    • Data Warehousing
    • Data Integration ETL


    Follow Us

    GST Registered: XXAXXXXXXXZX
    Mumbai, Maharashtra, India support@sqlforgeeks.com

    © 2025 Copyright™ | All Rights Reserved | Privacy Policy