Versions available for this page: CUBRID 8.2.1 | CUBRID 8.3.0 | CUBRID 8.3.1 | CUBRID 8.4.0 | CUBRID 8.4.1 | CUBRID 8.4.3 | CUBRID 9.0.0 |
The FROM clause specifies the table in which data is to be retrieved in the query. Retrieval paths are as follows:
• Single table
• Subquery
• Derived table
FROM from_specification
from_specification :
table_spec [ {, table_spec | outerjoin_table_spec }...]
table_spec :
single_table_spec [ correlation ] [ WITH (lock_hint [ {, lock_hint } ] ) ]
( single _table_spec [ {, single_table_spec}...] )
CLASS table_name [ correlation ]
subquery correlation
TABLE (expression) correlation
outerjoin_table_spec :
{ LEFT | RIGHT } [OUTER ] JOIN table_spec ON search_condition
single_table_spec :
[ ONLY ] table_name
ALL table_name [ ( EXCEPT table_spec ) ]
correlation :
[ AS ] identifier
lock_hint :
READ UNCOMMITTED
In the query statement, subqueries can be used in the table specification of the FROM clause. Such subqueries create derived tables where subquery results are treated as tables. A correlation specification must be used when a subquery that creates a derived table is used.
Derived tables are also used to access the individual element of an attribute that has a set value. In this case, an element of the set value is created as an instance in the derived table.
Each instance in the derived table is created from the result of the subquery in the FROM clause.
FROM (subquery) [ AS ] derived_table_name [( column_name [ {, column_name }_ ] )]
A derived table created form a subquery can have any number of columns and instances.
However, the number of column_name and the number of columns created by the subquery must be identical.
SELECT SUM(n) FROM (SELECT gold FROM participant WHERE nation_code='KOR'
UNION ALL SELECT silver FROM participant WHERE nation_code='JPN') AS t(n);
=== <Result of SELECT Command in Line 2> ===
sum(n)
========
82
1 rows selected.
SELECT nation_code, host_year, gold
FROM participant p
WHERE gold > ( SELECT AVG(s)
FROM ( SELECT silver + bronze
FROM participant
WHERE nation_code = p.nation_code
AND silver > 0
AND bronze > 0
) AS t(s));
=== <Result of SELECT Command in Line 1> ===
nation_code host_year gold
=========================================
'JPN' 2004 16
'CHN' 2004 32
'DEN' 1996 4
'ESP' 1992 13
4 rows selected.