ORDER BY

SQL ORDER BY Keyword

The ORDER BY clause is used to sort the results of a query in ascending (default) or descending order.

Tutorials dojo strip

SQL ORDER BY Syntax

SELECT column1, column2, ...
FROM table_name
ORDER BY column1 [ASC | DESC], column2 [ASC | DESC], ...;

SQL ORDER BY Default (Ascending) Example

This query selects all patients and sorts them by last_name in ascending order.

SELECT *
FROM Patients
ORDER BY last_name;

SQL ORDER BY ASC Example

This query selects all doctors and sorts them by specialty in ascending (A–Z) order.

SELECT *
FROM Doctors
ORDER BY specialty ASC;

SQL ORDER BY DESC Example

This query selects all appointments and sorts them by appointment_date in descending (latest first) order.

SELECT *
FROM Appointments
ORDER BY appointment_date DESC;

SQL ORDER BY Labs

Tutorials dojo strip
Scroll to Top