Sorting with ORDER BY · الفرز باستخدام ORDER BY
Sorting the result
The rows come back in no particular order. Add ORDER BY to sort them by a column:
ASCsorts ascending (smallest first) — this is the default.DESCsorts descending (largest first).
ترتيب النتائج
تُرجع الصفوف بدون ترتيب معين. أضف ORDER BY لترتيبها حسب عمود:
SELECT name, score FROM student ORDER BY score DESC;
ASCيرتب تصاعديًا (الأصغر أولًا) — وهذا هو الافتراضي.DESCيرتب تنازليًا (الأكبر أولًا).
Sorting by more than one column
Sort text columns alphabetically:
You can sort by several columns: ORDER BY form ASC, score DESC sorts by form first, then by score within each form. ORDER BY always comes last in the query.
الترتيب حسب أكثر من عمود
رتب أعمدة النص أبجديًا:
SELECT name FROM student ORDER BY name;
يمكنك الترتيب حسب عدة أعمدة: ORDER BY form ASC, score DESC يرتب حسب الصف أولاً، ثم حسب الدرجة داخل كل صف. تأتي ORDER BY دائمًا في النهاية في الاستعلام.
Common mistakes
- The default sort is ascending; add
DESCfor descending. ORDER BYcomes near the end of the query.
أخطاء شائعة
- الترتيب الافتراضي تصاعدي؛ أضف
DESCللتنازلي. ORDER BYتأتي靠近 نهاية الاستعلام.
ORDER BY sorts the rows · يقوم ORDER BY بترتيب الصفوف
ORDER BY puts the result rows in order, like a sort. · يضع ORDER BY صفوف النتيجة في ترتيب، مثل عملية الفرز.
Show every student's name and score, highest score first. · أظهر name و score لكل طالب، الأعلى درجة أولاً.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Show every student's name, sorted alphabetically (A to Z). · أظهر name لكل طالب، مرتباً تصاعدياً (من A إلى Z).
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.