The ASC keyword in SQL stands for "ascending" and is used to sort query results in ascending order, meaning from the lowest to the highest values (e.g., from A to Z for text, or from 1 to 10 for numbers).
It is often used with the ORDER BY clause to arrange the rows of a result set in a specific order. By default, ORDER BY sorts results in ascending order, so you can omit the ASC keyword, but it can be explicitly specified for clarity.
Example:
SELECT * FROM employees
ORDER BY salary ASC;
This query will return the employees sorted by their salary in ascending order (from the lowest to the highest salary). If you wanted to sort in descending order, you would use the DESC keyword instead of ASC.
Key Points:
- ASC: Sorts in ascending order (default behavior).
- DESC: Sorts in descending order (from highest to lowest).
No comments:
Post a Comment