Back to Yugabyte Db

ORDER BY

community/learn/content/01-SQL-Basics/02-fundamentals/02-order-by.md

2026.1.0.0-b29867 B
Original Source

SELECT with an ascending ORDER BY

In this exercise we sort employees by first_name in ascending order.

SELECT first_name,
       last_name,
       title,
       address,
       city
FROM employees
ORDER BY first_name ASC;

The query should return 9 rows.

SELECT with an descending ORDER BY

In this exercise we sort employees by first_name in descending order.

SELECT first_name,
       last_name,
       title,
       address,
       city
FROM employees
ORDER BY first_name DESC;

The query should return 9 rows.

SELECT with a ascending and descending ORDER BYs

In this exercise we sort employees by first_name in ascending order and then by last name in descending order.

SELECT first_name,
       last_name
FROM employees
ORDER BY first_name ASC,
         last_name DESC;

The query should return 9 rows