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:

Powered by AI
5 Prompts Remaining
Prompt AI WidgetOur tool is designed to help you to understand concepts and ask any follow up questions. Ask a question to get started.

Step 2: Run and observe

AI might ...

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