Sorting by Multiple Columns
You can sort by multiple columns. The first column is the primary sort, and subsequent columns break ties.
Multi-Column Sort Syntax
SELECT * FROM users ORDER BY column1, column2;
Each column can have its own ASC/DESC direction:
SELECT * FROM users ORDER BY city ASC, age DESC;
Exercises
Loading exercise...
Loading exercise...
Loading exercise...
Why Multi-Column Sorting Matters
Consider this scenario: you have multiple users in the same city. Without a secondary sort, their order within that city is undefined. Adding a second sort column ensures consistent, predictable results.
Loading exercise...
Free Practice
Loading SQL editor...
Try:
- Sort by age, then city
- Sort by city descending, then name ascending
- Add a filter and multi-column sort
التالي · الدرس 12 من 27
LIMIT and OFFSET
قراءة 1 دقيقة
أنهيت 11 من 27 درسًا

اسأل Byte عن هذا الدرس
محادثة خاصة حول هذا الدرس. قرأ Byte الدرس كاملًا، ويجيب خلال ثوانٍ، ويُظهر القسم الذي تأتي منه كل إجابة. يمكنك السؤال بأي لغة.
الأسئلة والأجوبة
أسئلة عامة حول هذا الدرس. يجيب AI Tutor فورًا بلغتك، ويراجع فريق FreeAcademy الإجابات، ويمكن لكل المتعلمين قراءتها.

