Order By Asc in SQL
ORDER BY ASC in SQL
ORDER BY ASC sorts the query results in ascending order (from smallest to largest).
? Syntax:
SELECT column1, column2, ...FROM table_nameORDER BY column_name ASC;ASCstands for ascending.This is the default sorting order in SQL, so
ORDER BY column_nameandORDER BY column_name ASCare equivalent.
? Example:
Get all employees ordered by their names in ascending order (A to Z):
SELECT employee_name, salaryFROM employeesORDER BY employee_name ASC;More example:
Order by salary ascending (lowest salary first):
SELECT employee_name, salaryFROM employeesORDER BY salary ASC;Notes:
You can use
ASCwith multiple columns:
ORDER BY department_id ASC, salary ASC;ASCis default, so you can omit it if you want.
Want me to explain ORDER BY DESC as well?