ORDER BY Syntax

Last updated: 2021-01-19 17:53:49

    The ORDER BY statement is used to sort results according to the specified KEY.
    The ORDER BY statement sorts records in ascending order by default.
    If you want to sort records in descending order, you can use the DESC keyword.

    ORDER BY Syntax Format

    ORDER BY column (KEY) [ DESC | ASC ]

    ORDER BY Syntax Sample

    Count different access status codes and sort them in descending order:

    SELECT status, COUNT(status) AS c GROUP BY status ORDER BY c DESC