encyclopegia.org

Order by

An ORDER BY clause in SQL specifies that a SQL SELECT statement returns a result set with the rows being sorted by the values of one or more columns.[src] The sort criteria do not have to be included in the result set (restrictions apply for SELECT DISTINCT , GROUP BY , UNION [DISTINCT] , EXCEPT [DISTINCT] and INTERSECT [DISTINCT] .) The sort criteria can be expressions, including column names, user-defined functions, arithmetic operations, or CASE expressions.[src] The expressions are evaluated and the results are used for the sorting, i.e., the values stored in the column or the results of the function call.[src] ORDER BY is the only way to sort the rows in the result set.[src] Without this clause, the relational database system may return the rows in any order.[src] If an ordering is required, the ORDER BY must be provided in the SELECT statement sent by the application.[src] Although some database systems allow the specification of an ORDER BY clause in subqueries or view definitions, the presence there has no effect on the final result-set order, but makes sense when combined with a result offset clause or a fetch first clause.[src] A view is a logical relational table, and the relational model mandates that a table is a set of rows, implying no sort order whatsoever.[src] The only exception are constructs like ORDER BY ORDER OF ...…[src]

An ORDER BY clause in SQL specifies that a SQL SELECT statement returns a result set with the rows being sorted by the values of one or more columns.[src] The sort criteria do not have to be included in the result set (restrictions apply for SELECT DISTINCT , GROUP BY , UNION [DISTINCT] , EXCEPT [DISTINCT] and INTERSECT [DISTINCT] .) The sort criteria can be expressions, including column names, user-defined functions, arithmetic operations, or CASE expressions.[src] The expressions are evaluated and the results are used for the sorting, i.e., the values stored in the column or the results of the function call.[src] ORDER BY is the only way to sort the rows in the result set.[src] Without this clause, the relational database system may return the rows in any order.[src] If an ordering is required, the ORDER BY must be provided in the SELECT statement sent by the application.[src] Although some database systems allow the specification of an ORDER BY clause in subqueries or view definitions, the presence there has no effect on the final result-set order, but makes sense when combined with a result offset clause or a fetch first clause.[src] A view is a logical relational table, and the relational model mandates that a table is a set of rows, implying no sort order whatsoever.[src] The only exception are constructs like ORDER BY ORDER OF ...[src] (not standardized in SQL:2003) which allow the propagation of sort criteria through nested subqueries.[src] The SQL standard's core functionality does not explicitly define a default sort order for Nulls.[src] With the SQL:2003 extension T611, "Elementary OLAP operations", nulls can be sorted before or after all data values by using the NULLS FIRST or NULLS LAST clauses of the ORDER BY list, respectively.[src] Not all DBMS vendors implement this functionality, however.[src] Vendors who do not implement this functionality may specify different treatments for Null sorting in the DBMS.[src] Structure ORDER BY ...[src] DESC will order in descending order, otherwise ascending order is used.[src] (The latter may be specified explicitly using ASC .) SELECT * FROM Employees ORDER BY LastName, FirstName This sorts by the LastName column, then by the FirstName column if LastName matches.[src]

26 sentences · 26 cited inline · 1 references stored

References

  1. NULL Handling in SQLite Versus Other Database Engines . retrieved January 25, 2009 · retrieved 2026-03-19 · rev 1344406702
    Cite this reference

    MLA "NULL Handling in SQLite Versus Other Database Engines . retrieved January 25, 2009." NULL Handling in SQLite Versus Other Database Engines. 2026-03-19. https://en.wikipedia.org/w/index.php?oldid=1344406702. Accessed 29 November 2026.

    Chicago "NULL Handling in SQLite Versus Other Database Engines . retrieved January 25, 2009." NULL Handling in SQLite Versus Other Database Engines. 2026-03-19. https://en.wikipedia.org/w/index.php?oldid=1344406702.

    APA NULL Handling in SQLite Versus Other Database Engines. (2026). NULL Handling in SQLite Versus Other Database Engines . retrieved January 25, 2009. Retrieved November 29, 2026, from https://en.wikipedia.org/w/index.php?oldid=1344406702

Cite this article

MLA

"Order by." encyclopegia.org, 2026, https://encyclopegia.org/wiki/order-by. Accessed 29 November 2026.

Chicago

"Order by." encyclopegia.org. Accessed November 29, 2026. https://encyclopegia.org/wiki/order-by.

APA

encyclopegia.org. (2026). Order by. Retrieved November 29, 2026, from https://encyclopegia.org/wiki/order-by

Accessed November 29, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Order of the British Empire

stub · references available

Order of Railroad Telegraphers

stub · references available

Corinthian order

stub · references available

Order of African Redemption

stub · references available

Order of the Golden Spur

stub · references available

National Order of the Cedar

stub · references available

Honorary Order of the Yellow Star

stub · references available

Order of the Oak Crown

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1344406702 · 0.5 · snapshot enwiki-001344406702

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners
  • Index — every corpus, paper and record
  • Estate guide — what a public data estate is
  • Founder — Lois-Kleinner Alpasan
  • Records — DOIs and external deposits
  • Documents — one-pagers, PDFs and QR codes
  • Brand kit — logos and share images
  • Papers — plain-language briefs with citations
  • Browser — search engine, PWA and bookmarklet
  • Anticloud — the operator and its projects

As seen in Business Insider · 336 outlets · evidence DOIs · plain-language papers

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.