By default, ORDER BY sorts ascending (ASC). Use DESC to sort descending.
SQL & Relational Databases
SQL Tutorial
SQL Database
Advertisement
Google AdSense Slot (LEADERBOARD)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Sorting
7 min read
•
Chapter 7 of 20
SQL ORDER BY
The ORDER BY keyword is used to sort the result-set in ascending or descending order (ASC or DESC).
Example
<!DOCTYPE html>
<html>
<body style="font-family:monospace;padding:20px;">
<pre>SELECT * FROM Stocks ORDER BY market_cap DESC;</pre>
</body>
</html>
Try it Yourself >>
Opens live sandboxed code editor
Advertisement
Google AdSense Slot (IN-ARTICLE)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Community Q&A & Discussion
Verified
No questions yet. Be the first to start the discussion!