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. · לחץ על הרץ כדי לראות את התוצא כאן.