QuestDB LogoQuestDB Logo
Return to QuestDB.comDocumentationTutorialsBlogQuestDB EnterprisePublic SlackDiscourse CommunityView QuestDB Repo
⚡️ QuestDB Enterprise
9.3.3|16.7k
  • Release Notes
  • Roadmap
  • Introduction
  • Schema design
  • Getting Started
  • Ingestion Reference
  • Query & SQL Reference
    • Overview
    • PostgreSQL Wire Protocol
    • REST HTTP API
    • Parquet Export
    • Data Types
    • SQL Syntax
      • ADD USER
      • ALTER
      • ASSUME SERVICE ACCOUNT
      • BACKUP
      • CANCEL QUERY
      • CHECKPOINT
      • COMPILE VIEW
      • COPY
      • CREATE
      • DROP
      • EXIT SERVICE ACCOUNT
      • EXPLAIN
      • GRANT
      • INSERT
      • LOAD PLUGIN
      • REFRESH MATERIALIZED VIEW
      • REINDEX
      • RELOAD PLUGIN
      • REMOVE USER
      • RENAME TABLE
      • REVOKE
      • SELECT
        • SELECT OVERVIEW
        • ASOF JOIN
        • CASE
        • CAST
        • DECLARE
        • DISTINCT
        • FILL
        • GROUP BY
        • HORIZON JOIN
        • JOIN
        • LATEST ON
        • LIMIT
        • ORDER BY
        • PIVOT
        • SAMPLE BY
        • WHERE
        • WINDOW JOIN
        • WITH
      • SCAN PLUGINS
      • SHOW
      • SNAPSHOT
      • TRUNCATE TABLE
      • UNION EXCEPT INTERSECT
      • UNLOAD PLUGIN
      • UPDATE
      • VACUUM TABLE
    • SQL execution order
    • Functions
    • Operators
  • Concepts
  • Architecture
  • Configuration
  • Security
  • High Availability
  • Operations
  • Deployment
  • Integrations
  • Tutorials & Cookbook
  • Troubleshooting
  • Release Notes
  • Query & SQL Reference
  • 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
PIVOT
  • Syntax
  • Notes
  • Examples

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

Copyright © 2026 QuestDB
PrivacyTerms