Search⌘ K
AI Features

ORDER BY and LIMIT

Explore how to use ORDER BY to sort SQL query results and LIMIT to restrict the number of rows returned. Learn to combine filtering, sorting, and limiting to retrieve focused insights, such as top salaries in specific departments. Practice adjusting queries to sharpen your data analysis skills.

Step 1: Start with a question

You already know how to ask which rows to show. Now, let’s ask in what order. Imagine your familiar table employees.

What if you wanted to see who earns the most?

You would surely want to see all employees, sorted by salary from highest to lowest.

Prompt: Write a SQL query that lists employee first name, last name, and salary, sorted by salary from highest to lowest.

Ask AI to translate that question into SQL:

AI Powered
Saved
5 Attempts Remaining
Reset

Step 2: Run and observe

AI might ...

MySQL
SELECT first_name, last_name, salary
FROM employees
ORDER BY salary DESC;
...