SQL SELECT: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:
A query consists in at least one (<code>[[#SELECT|SELECT]]</code>) and at most six categories of [[#Clauses|clauses]]:
A query consists in at least one (<code>[[#SELECT|SELECT]]</code>) and at most six categories of [[#Clauses|clauses]]:
<font>
<font>
  [[#SELECT|SELECT]] [...] [[#FROM|FROM]] [...] [[#WHERE|WHERE]] [...] GROUP BY [...] HAVING [...] ORDER BY [...]
  [[#SELECT|SELECT]] [...] [[#FROM|FROM]] [...] [[#WHERE|WHERE]] [...] GROUP BY [...] HAVING [...] ORDER BY [...];
</font>
</font>



Revision as of 23:15, 22 May 2024

Internal

Overview

A query consists in at least one (SELECT) and at most six categories of clauses:

SELECT [...] FROM [...] WHERE [...] GROUP BY [...] HAVING [...] ORDER BY [...];

The following query:

SELECT;

is valid, it returns one empty row.

Upon execution, an SQL query returns a result set.


Select all (possibly across multiple tables) then filter and discard with where.

Example

SELECT id, name FROM person WHERE id = 1;

Clauses

SELECT

FROM

FROM permanent|derived|temporary|virtual(view)

Table alias.

Querying Multiple Tables

Querying Multiple Tables

WHERE

The WHERE Clause

GROUP BY ... HAVING

GROUP BY ... HAVING

ORDER BY

Subqueries