ASC

ASC stands for ascending. It is an optional keyword used in the ORDER BY clause to sort data in ascending order. The default order is ascending, so its usage is often omitted.

Example

SELECT * FROM Employees
ORDER BY LastName ASC;

Output

| EmployeeID | LastName | FirstName | Department |
| ---------- | -------- | --------- | ---------- |
| 4 | Adams | Amy | HR |
| 2 | Brown | Brian | Sales |
| 3 | Clark | Chris | IT |
| 1 | Davis | David | Marketing |

Explanation

In the SQL code above, SELECT * FROM Employees is used to retrieve all records from the Employees table. The ORDER BY LastName ASC clause is used to sort the records in ascending order based on the LastName column. The resulting output contains all employee records, organized in an ascending order with respect to the last names.

Example

SELECT *
FROM employees
ORDER BY last_name ASC;

Output

last_name | first_name | hire_date
----------|------------|------------
Adams | John | 2003-07-07
Allen | Mark | 2003-08-20
Blake | Marion | 2003-03-11
Clark | Ruben | 2003-06-14
Davis | Rafael | 2003-09-30

Explanation

The given SQL statement fetches all records from the employees table and orders them by the last_name column in ascending (ASC) order.

Example

SELECT * FROM Employees
ORDER BY LastName ASC;

Output

| EmployeeID | LastName | FirstName | Title |
|------------|----------|-----------|-------------|
| 1 | Doe | Jane | Manager |
| 2 | Johnson | John | Sales |
| 3 | Smith | Steve | IT Specialist |

Explanation

The SQL statement selects all records from the Employees table and orders them in ascending order (ASC) by the LastName column. The output displays EmployeeID, LastName, FirstName and Title of all employees, sorted by LastName in alphabetical order A-Z (as arranged by ASCII values).

Example

SELECT *
FROM Employees
ORDER BY Salary ASC;

Output

| Employee_ID | First_Name | Last_Name | Salary |
|-------------|------------|-----------|--------|
| 1 | John | Doe | 3000 |
| 3 | Jane | Smith | 3200 |
| 2 | Tim | Taylor | 3500 |

Explanation

The SQL code selects all columns from the ‘Employees’ table and orders the resulting records in ascending order by the ‘Salary’ column. In the output, the Employee records are ordered from the lowest to the highest salary.

Example

SELECT * FROM Employees
ORDER BY Last_Name ASC;

Output

| ID | Last_Name | First_Name | Salary |
|----|-----------|------------|--------|
| 1 | Anderson | John | 45000 |
| 2 | Brown | Lucy | 60000 |
| 3 | Davis | Kate | 48000 |
| 4 | Evans | Mike | 55000 |

Explanation

The SQL code provided above selects all records from the “Employees” table and then sorts the output in ascending (ASC) order based on the “Last_Name” column. This means that the records are displayed alphabetically from A-Z based on the last names of the employees.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.