QuestDB LogoQuestDB Logo
Return to QuestDB.comDocumentationTutorialsBlogEnterprisePublic SlackDiscourse CommunityView QuestDB Repo
⚡️ QuestDB Enterprise
9.2.3|16.5k
  • Release Notes
  • Roadmap
  • Getting Started
    • Introduction
    • Quick start
    • Why QuestDB?
    • Schema Design Essentials
    • Capacity planning
    • Create a sample database
    • Upgrade to Enterprise
    • Enterprise Quick Start
    • Web Console
  • Connect & Ingest
  • Query Data
    • Query & SQL Overview
    • Data Types
      • Overview
      • N-Dim array
      • Decimal
      • Geospatial data
    • SQL execution order
    • SQL Syntax
      • ADD USER
      • ALTER
      • ASSUME SERVICE ACCOUNT
      • CANCEL QUERY
      • CHECKPOINT
      • COMPILE VIEW
      • COPY
      • CREATE
      • DROP
      • EXIT SERVICE ACCOUNT
      • EXPLAIN
      • GRANT
      • INSERT
      • REFRESH MATERIALIZED VIEW
      • REINDEX
      • REMOVE USER
      • RENAME TABLE
      • REVOKE
      • SELECT
        • SELECT OVERVIEW
        • ASOF JOIN
        • CASE
        • CAST
        • DECLARE
        • DISTINCT
        • FILL
        • GROUP BY
        • JOIN
        • WINDOW JOIN
        • LATEST ON
        • LIMIT
        • ORDER BY
        • OVER
        • SAMPLE BY
        • WHERE
        • WITH
      • SHOW
      • SNAPSHOT
      • TRUNCATE TABLE
      • UNION EXCEPT INTERSECT
      • UPDATE
      • VACUUM TABLE
    • Functions
    • Operators
  • Concepts
  • Architecture
  • Configuration
  • Security
  • High Availability
  • Operations
  • Deployment
  • Integrations
  • Tutorials
  • Troubleshooting
  • Release Notes
  • Query Data
  • SQL Syntax
  • SELECT
  • ORDER BY

ORDER BY keyword

Sort the results of a query in ascending or descending order.

Syntax​

Flow chart showing the syntax of the ORDER BY keyword

Default order is ASC. You can omit to order in ascending order.

Notes​

Ordering data requires holding it in RAM. For large operations, we suggest you check you have sufficient memory to perform the operation.

Examples​

Omitting ASC will default to ascending order
ratings ORDER BY userId;
Ordering in descending order
ratings ORDER BY userId DESC;
Multi-level ordering
ratings ORDER BY userId, rating DESC;
Edit this page
Previous
LIMIT
Next
OVER
  • Syntax
  • Notes
  • Examples

Need a hand? Join our vibrant public Slack and Discourse forum communities.

Copyright © 2025 QuestDB
PrivacyTerms