SELECT
command is basically done in three steps:
FROM
clause.
WHERE
clause.
SELECT
clause; DISTINCT
may be added to avoid duplicate tuples in the result.
R
be a relational schema with a set of attributes X
, where {A1
, ..., Ak
} is contained in X
.
The project of R
onto {A1
, ..., Ak
} is expressed by
SELECT DISTINCT A1, ... Ak FROM R SQL> SELECT DISTINCT class FROM student; |
R
and S
be relational schemata with equal sets of attributes.
The union of R
and S
is expressed by
SELECT DISTINCT * FROM R UNION SELECT DISTINCT * FROM S SQL> SELECT DISTINCT * FROM ( SELECT last_name FROM student ) 2 UNION 3 SELECT DISTINCT * FROM ( SELECT first_name FROM student ); |
“The secret of life, though, is to fall seven times and to get up eight times.” ― Paulo Coelho, The Alchemist |