FROM clause

The FROM clause specifies the source of the data that the query should work with. Logically, the FROM clause is the place where the query execution starts.

A FROM clause can contain a single table, a combination of multiple tables joined using JOIN, or another query SELECT in a subquery node.

Syntax

SELECT ...
FROM {
      [<schema_name>.]<table_name>
            [ [ AS ] <alias_name> ]
      | <subquery>
            [ [ AS ] <alias_name> ]
      }
[ JOIN ... ]

Parameters

  • [<schema_name>.]<table_name>
    Specifies the name of the object (table or view) being queried. Optionally, a schema name is specified. If no schema name is specified, the default schema will be used.


  • <subquery>
    SELECT subquery in a FROM expression.


  • [ AS ] <alias_name>
    Specifies the name (alias) of the object. The AS operator may be omitted.


  • JOIN
    Indicates the execution of a join between two (or more) tables (or views).
    For a detailed description, see JOIN clause.

Examples

  • Select all columns from the table named my_table:

    SELECT *
    FROM my_table;
  • Select all columns from a table named my_table through the alias mt:

    SELECT mt.*
    FROM my_table mt;
  • Using the prefix alias:

    SELECT mt.*
    FROM mt: my_table;
  • Select all columns from the my_table table in the my_schema schema:

    SELECT *
    FROM my_schema.my_table;
  • Select all columns from the subquery:

    SELECT *
    FROM (SELECT * FROM my_table);
  • Merge the two tables:

    SELECT *
    FROM my_table
    JOIN other_table
        ON my_table.key = other_table.key;

    For a detailed description, see JOIN clause.