SQL Keywords

SQL ASC

What is SQL ASC?

ASC specifies ascending sort order in an ORDER BY clause.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL ASC: PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, BigQuery, DuckDB

SQL ASC Full Explanation

ASC (short for "ascending") is an optional keyword used in the ORDER BY clause to sort query results from lowest to highest. Numbers ascend from small to large, text ascends alphabetically according to the database collation, and dates ascend from earliest to latest. Because ascending order is the default, omitting ASC produces the same output, but specifying it makes intent explicit and lets you mix ASC and DESC on multiple columns. ASC affects only the presentation of rows; it does not change the underlying table data. Performance depends on indexes that match the ORDER BY columns. When NULLS are present, most dialects place them either first or last depending on vendor rules unless NULLS FIRST or NULLS LAST is added.

SQL ASC Syntax

SELECT column_list
FROM table_name
ORDER BY column_name ASC;

SQL ASC Parameters

Example Queries Using SQL ASC

-- Sort users by last name (alphabetical)
SELECT id, last_name, first_name
FROM users
ORDER BY last_name ASC;

-- Mix ascending and descending
SELECT id, total, created_at
FROM orders
ORDER BY total ASC, created_at DESC;

-- Ascending date example
SELECT event_id, event_date
FROM events
WHERE event_date >= CURRENT_DATE - INTERVAL '30 days'
ORDER BY event_date ASC;

Expected Output Using SQL ASC

  • Rows are returned in ascending order based on the specified column(s)
  • Numeric columns list smaller values first, text columns list A-Z, and dates list oldest to newest

Use Cases with SQL ASC

  • Alphabetically list customer names in a UI grid
  • Generate ranked reports where lowest metric appears first
  • Display events in chronological order
  • Create deterministic ordering before using LIMIT or FETCH for pagination

Common Mistakes with SQL ASC

  • Forgetting that ASC is the default and redundantly writing it everywhere
  • Expecting ASC to override database collation when sorting text
  • Assuming NULLS sort the same across databases without specifying NULLS FIRST or NULLS LAST
  • Using ASC on columns without supporting indexes, leading to slow queries

Related Topics

ORDER BY, DESC, NULLS FIRST, NULLS LAST, COLLATE

First Introduced In

SQL-86

Frequently Asked Questions

What does ASC stand for in SQL?

ASC means "ascending" and tells the database to order the result set from lowest to highest.

Is ASC required in every ORDER BY clause?

No. If you omit ASC or DESC, most databases default to ascending order, but explicitly stating ASC improves readability.

How are NULL values sorted when I use ASC?

Default NULL placement varies by database. Use NULLS FIRST or NULLS LAST to control the exact position.

Can I combine ASC and DESC in the same query?

Yes. Specify ASC or DESC after each column in the ORDER BY clause to mix sort directions.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!