Sql - Sorting with ORDER BY
Code Life
By Pierre Marsaa
Introduction to Sorting with ORDER BY
The ORDER BY clause in SQL allows you to sort your query results in a specific order. By default, results from a SELECT query are returned in no particular order.
Here's the basic syntax of ORDER BY:
Loading editor...
Let's try sorting our Codémon by their power:
Loading data...
↗️
Loading editor...
↶
↷
By default, ORDER BY sorts in ascending order (smallest to largest, A to Z). Notice how the Codémon are now arranged from lowest power to highest power.
ORDER BY Position in Query
ORDER BY always comes after the FROM clause (and any WHERE clause if present), but before LIMIT if you're using it.
Verify