முக்கிய உள்ளடக்கத்திற்குச் செல்லவும்
eLearner.app
தொகுதி 1 · பாடம் 4 இன் 4பாடத்திட்டத்தில் 4/57~8 min
தொகுதி பாடங்கள் (4/4)

ஆர்டர் மூலம் வரிசைப்படுத்துதல்

SQL does not guarantee the order of the rows returned by a SELECT: if you want a deterministic order, you have to ask for it explicitly with ORDER BY:

SQL
SELECT <colonne>
FROM   <tabella>
[WHERE <condizione>]
ORDER BY <colonna> [ASC|DESC] [, <altra-colonna> [ASC|DESC] …];
  • ASC is the default: ascending order (1 → 9, A → Z, old → recent).
  • DESC sorts descending (9 → 1, Z → A, recent → old).
  • You can sort by multiple columns: the second criterion breaks ties of the first.

Examples

SQL
-- Dal più recente assunto al più vecchio:
SELECT first_name, last_name, hired_on
FROM employees
ORDER BY hired_on DESC;

-- Per dipartimento crescente, poi per stipendio decrescente:
SELECT *
FROM employees
ORDER BY department_id, salary DESC;

Try it

உடற்பயிற்சி#sql.m1.l4.e1
முயற்சிகள்: 0ஏற்றுகிறது…

Extract last name (last_name) and salary (salary) of all employees, sorted from the highest salary to the lowest.

எடிட்டரை ஏற்றுகிறது…
குறிப்பைக் காட்டு

ORDER BY salary DESC puts the highest-paid employees first.

3 முயற்சிகளுக்குப் பிறகு தீர்வு கிடைக்கும்

Review exercise

உடற்பயிற்சி#sql.m1.l4.e2
முயற்சிகள்: 0ஏற்றுகிறது…

Extract last name (last_name), department_id and salary (salary) of all employees, sorted first by department_id ascending and, within the same department, from the highest salary to the lowest.

எடிட்டரை ஏற்றுகிறது…
குறிப்பைக் காட்டு

You can pass two columns separated by a comma to ORDER BY, each with its own ASC or DESC.

3 முயற்சிகளுக்குப் பிறகு தீர்வு கிடைக்கும்