Junior — Middle
What sorting and filtering methods of data with SQL are you familiar with?
sobes.tech AI
Answer from AI
The following methods are used for sorting and filtering data in SQL:
- Sorting: the
ORDER BYoperator. It allows sorting data by one or more columns in ascending (ASC) or descending (DESC) order.
SELECT * FROM employees ORDER BY salary DESC;
- Filtering: the
WHEREoperator. It allows selecting rows that meet certain conditions.
SELECT * FROM employees WHERE department = 'Sales';
- Combining filtering and sorting:
SELECT * FROM employees WHERE age > 30 ORDER BY last_name ASC;
For more complex filtering, operators like LIKE, IN, BETWEEN can be used, and for sorting — multiple columns with different sorting directions.