Day 56 – SQL ASC Keyword
SQL ASC keyword is used in the ORDER BY clause of a SELECT statement to sort the result set in ascending order.
The syntax for using the ASC keyword is as follows:
SELECT column_name(s) FROM table_name ORDER BY column_name ASC;
column_name is the name of the column by which you want to sort the result set in ascending order.
For example, the following SQL statement selects all the customers from the “Customers” table and sorts them in ascending order by their last names:
SELECT * FROM Customers ORDER BY LastName ASC;
In this case, the result set is sorted in ascending order by the values in the LastName column.
Note that the ASC keyword is optional in SQL, as the default sorting order is ascending. So, the above example can also be written without the ASC keyword, like this:
SELECT * FROM Customers ORDER BY LastName;
Both of these statements will produce the same result set, sorted in ascending order by the values in the LastName column.