SQL SELECT: Difference between revisions
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]] <font color=teal>[one or more things]</font> [[#FROM|FROM]] [ | [[#SELECT|SELECT]] <font color=teal>[one or more things]</font> | ||
[[#FROM|FROM]] <font color=teal>[one or more places]</font> | |||
[[#WHERE|WHERE]] <font color=teal>[one or more conditions apply]</font> | |||
[[SQL_GROUP_BY#Overview|GROUP BY]] [...] [[SQL_GROUP_BY#Overview|HAVING]] [...] | |||
[[#ORDER_BY|ORDER BY]] [...]; | |||
</font> | </font> | ||
Revision as of 23:20, 22 May 2024
Internal
Overview
A query consists in at least one (SELECT
) and at most six categories of clauses:
SELECT [one or more things] FROM [one or more places] WHERE [one or more conditions apply] GROUP BY [...] HAVING [...] ORDER BY [...];
Almost every query will include at least three of these clauses (SELECT
, FROM
and WHERE
).
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;
The following query:
SELECT;
is valid, it returns one empty row.
Clauses
SELECT
FROM
FROM permanent|derived|temporary|virtual(view)
Table alias.