Search⌘ K

ORDER BY and LIMIT

Learn how to sort columns in SQL table.

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 produce:

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

 Run it. ...