- 1998-09-06
+ 1998-09-24
SELECT [ALL|DISTINCT]
- expression [AS name] [, ...]
- [INTO [TABLE] intable]
- [FROM table [alias] [, ...] ]
- [WHERE condition]
- [GROUP BY column [, ...] ]
- [HAVING condition [, ...] ]
- [UNION [ALL] select]
- [ORDER BY column [ASC | DESC] [, ...] ]
+ expression [ AS name ] [, ...]
+ [ INTO [TABLE] new_table ]
+ [ FROM table [alias ] [, ...] ]
+ [ WHERE condition ]
+ [ GROUP BY column [, ...] ]
+ [ HAVING condition [, ...] ]
+ [ UNION [ALL] select ]
+ [ ORDER BY column [ ASC | DESC ] [, ...] ]
- 1998-09-06
+ 1998-09-24
Inputs
- intable
+ new_table
If the INTO TABLE clause is specified, the result of the
query will be stored in another table with the indicated
name.
- If intable does
+ If new_table does
not exist, it will be created automatically.
-
+ Refer to SELECT INTO for more information.
The CREATE TABLE AS statement will also
- 1998-09-06
+ 1998-09-24
Outputs
+
- count
+ status
+
+
+
+
+
+
+ count
+
- 1998-09-06
+ 1998-09-24
Description
- SELECT will get all rows which satisfy the WHERE condition
+ SELECT will get all rows which satisfy the
+ WHERE condition
or all rows of a table if WHERE is omitted.
You must have SELECT privilege to a table to read its values
- (See GRANT/REVOKE statements).
+ (See GRANT/REVOKE statements).
+
- 1998-09-06
+ 1998-09-24
- WHERE clause
+ WHERE Clause
The optional WHERE condition has the general form:
-WHERE expr cond_op expr [log_op ...]
+WHERE expr cond_op expr [ log_op ... ]
where cond_op can be
- 1998-09-06
+ 1998-09-24
- GROUP BY clause
+ GROUP BY Clause
GROUP BY specifies a grouped table derived by the application
of the this clause:
- GROUP BY column [, ...]
+GROUP BY column [, ...]
- 1998-09-06
+ 1998-09-24
- HAVING clause
+ HAVING Clause
The optional HAVING condition has the general form:
that do not meet the cond_expr.
- Each column referenced in cond_expr shall unambiguously
+ Each column referenced in
+cond_expr shall unambiguously
reference a grouping column.
- 1998-09-06
+ 1998-09-24
- ORDER BY clause
+ ORDER BY Clause
-ORDER BY column [ASC | DESC] [, ...]
+ORDER BY column [ ASC | DESC ] [, ...]
The ordinal numbers refers to the ordinal (left-to-right) position
of the column. This feature makes it possible to define an ordering
on the basis of a column that does not have a proper name.
- This is never absolutely necessary because it is always possible assign a name
+ This is never absolutely necessary because it is always possible
+ assign a name
to a calculated column using the AS clause, e.g.:
- SELECT title, date_prod + 1 AS newlen FROM films ORDER BY newlen;
+SELECT title, date_prod + 1 AS newlen FROM films ORDER BY newlen;
The columns in the ORDER BY must appear in the SELECT clause.
Thus the following statement is illegal:
- SELECT name FROM distributors ORDER BY code;
+SELECT name FROM distributors ORDER BY code;
- 1998-09-06
+ 1998-09-24
- UNION clause
+ UNION Clause
-table_query UNION [ALL] table_query
- [ORDER BY column [ASC | DESC] [, ...] ]
+table_query UNION [ ALL ] table_query
+ [ ORDER BY column [ ASC | DESC ] [, ...] ]
where
unless the ALL clause is specified.
- Multiple UNION operators in the same SELECT statement are evaluated left to right.
- Note that the ALL keyword is not global in nature, being applied only for the current pair of
- table results.
+ Multiple UNION operators in the same SELECT statement are
+evaluated left to right.
+ Note that the ALL keyword is not global in nature, being
+applied only for the current pair of table results.
distributors:
- SELECT f.title, f.did, d.name, f.date_prod, f.kind
- FROM distributors d, films f
- WHERE f.did = d.did
+SELECT f.title, f.did, d.name, f.date_prod, f.kind
+ FROM distributors d, films f
+ WHERE f.did = d.did
title |did|name | date_prod|kind
-------------------------+---+----------------+----------+----------
the reults by kind:
- SELECT kind, SUM(len) AS total FROM films GROUP BY kind;
+SELECT kind, SUM(len) AS total FROM films GROUP BY kind;
kind |total
----------+------
that are less than 5 hours:
- SELECT kind, SUM(len) AS total
- FROM films
- GROUP BY kind
- HAVING SUM(len) < INTERVAL '5 hour';
+SELECT kind, SUM(len) AS total
+ FROM films
+ GROUP BY kind
+ HAVING SUM(len) < INTERVAL '5 hour';
kind |total
----------+------
(name):
- SELECT * FROM distributors ORDER BY name;
- SELECT * FROM distributors ORDER BY 2;
+SELECT * FROM distributors ORDER BY name;
+SELECT * FROM distributors ORDER BY 2;
did|name
---+----------------
-- 112|Warner Bros. 3|Walter Matthau
-- ... ...
- SELECT distributors.name
+SELECT distributors.name
FROM distributors
WHERE distributors.name LIKE 'W%'
- UNION
- SELECT actors.name
- FROM actors
- WHERE actors.name LIKE 'W%'
+UNION
+SELECT actors.name
+ FROM actors
+ WHERE actors.name LIKE 'W%'
name
--------------
- 1998-09-06
+ 1998-09-24
1998-04-15
- SELECT clause
+ SELECT Clause
In the
SQL92 standard, the optional keyword "AS"
- 1998-09-06
+ 1998-09-24
- UNION clause
+ UNION Clause
The
SQL92 syntax for UNION allows an
+
+
+
+ SELECT
+
+ SQL - Language Statements
+
+
+
+ SELECT INTO
+
+
+ Create a new table from an existing table or view
+
+
+
+ 1998-09-22
+
+
+SELECT [ ALL | DISTINCT ] expression [ AS name ] [, ...]
+ INTO [ TABLE ] new_table ]
+ [ FROM table [alias] [, ...] ]
+ [ WHERE condition ]
+ [ GROUP BY column [, ...] ]
+ [ HAVING condition [, ...] ]
+ [ UNION [ ALL ] select]
+ [ ORDER BY column [ ASC | DESC ] [, ...] ]
+
+
+
+
+ 1998-09-22
+
+
+ Inputs
+
+All input fields are described in detail for SELECT.
+
+
+
+ 1998-09-22
+
+
+ Outputs
+
+All output fields are described in detail for SELECT.
+
+
+
+ 1998-09-22
+
+
+ Description
+
+SELECT INTO creates a new table from the results of a query. Typically, this
+query draws data from an existing table, but any SQL query is allowed.
+
+CREATE TABLE AS is functionally equivalent to the SELECT INTO command.
+
+
+
+
+
-1998-08-31
+1998-09-24
SHOW variable
-1998-08-31
+1998-09-24
Inputs
-
+
- Refer to the SET statement for more information on available
+ Refer to SET for more information on available
variables.
-1998-08-31
+1998-09-24
Outputs
-
+
+
+
+
+status
+
+
+
-NOTICE: variable is value
+NOTICE: variable is value
SHOW VARIABLE
Message returned if successfully.
+
-NOTICE: Unrecognized variable value
+NOTICE: Unrecognized variable value
+
Message returned if value does not exist.
+
+
+
+NOTICE: Time zone is unknown
+SHOW VARIABLE
+
+
+ If the TZ environment variable is not set.
+
+
+
-1998-08-31
+1998-09-24
Description
- SHOW will display the current configuration parameters for
+ SHOW will display the current
+ configuration parameters for
variable during a session.
- The session can be configured using SET statement, and values
- can be restored to the defaults using RESET statement.
+ The session can be configured using SET statement,
+ and values
+ can be restored to the defaults using RESET statement.
Parameters and values are case-insensitive.
-1998-08-31
+1998-09-24
Notes
- The
SHOW statement is a
Postgres
language extension.
- Refer to the SET/RESET statements to set/reset variable values.
- See also the SET TIME ZONE statement.
+ Refer to SET/RESET
+ to set/reset variable values.
+ See also SET TIME ZONE.
- If the TZ environment variable is not set the SHOW TIME ZONE statement
- gives the message: Time zone is unknown
- -- show DateStyle;
- SHOW DateStyle;
- NOTICE:DateStyle is Postgres with US (NonEuropean) conventions
+-- show DateStyle;
+SHOW DateStyle;
+NOTICE:DateStyle is Postgres with US (NonEuropean) conventions
- -- show Geqo;
- SHOW GEQO;
- NOTICE:GEQO is ON
+-- show Geqo;
+SHOW GEQO;
+NOTICE:GEQO is ON
-1998-08-31
+1998-09-24
SQL92
- There is no
SET statement defined in
SQL92.
+ There is no
SET defined in
SQL92.