Suggest an editImprove this articleRefine the answer for “How do you sort by multiple fields?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)To sort data **by multiple fields**, list several columns after `ORDER BY`, separated by commas, e.g. `ORDER BY department ASC, salary DESC` - SQL sorts **in the order the fields are listed**: first by the first field, then within each group by the second, and so on. **Key point:** each field can be sorted in its own direction (`ASC` or `DESC`) independently of the others.Shown above the full answer for quick recall.Answer (EN)ImageTo sort data **by multiple fields**, list **several columns separated by commas** after `ORDER BY`. ### Syntax ```sql SELECT * FROM table_name ORDER BY field1 [ASC|DESC], field2 [ASC|DESC], field3 [ASC|DESC]; ``` SQL sorts **in the order the fields are listed**: first by the first one, then within each group by the second, and so on. ### Example ```sql SELECT name, department, salary FROM employees ORDER BY department ASC, salary DESC; ``` What happens: 1. First, all rows are grouped by department, alphabetically (`ASC`); 2. Within each department, employees are sorted by salary, from largest to smallest (`DESC`). ### Another example ```sql SELECT city, last_name, first_name FROM clients ORDER BY city ASC, last_name ASC, first_name ASC; ``` First clients are sorted by city, then within that, by last name, and if the last name matches, by first name. **Summary:** `ORDER BY` can contain several fields, SQL applies the sort **sequentially**, left to right. Each field can be sorted **in its own direction** (`ASC` or `DESC`).For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.