FROM clause

The source of the rows for the query is specified after the FROM keyword. It is called the FROM clause. The query can select rows from zero, one, or more sources. When no source is specified, the FROM keyword should be omitted. The source of the rows for the query can be any of the following:

  • Table
  • View
  • Function
  • Subquery
  • VALUES

When multiple sources are specified, they should be separated by a comma or the JOIN clause should be used.

It is possible to set aliases for tables in the FROM clause. The optional keyword AS is used for that:

car_portal=> SELECT a.car_id, a.number_of_doors FROM car_portal_app.car AS a; 
car_id | number_of_doors
--------+-----------------
1 | 5
2 | 3
3 | 5
...

In the preceding example, the table name car_portal_app.car was substituted with its alias a in the select-list. If an alias is used for a table or view in the FROM clause, in the select-list (or anywhere else) it is no longer possible to refer to the table by its name. Subqueries when used in the FROM clause must have an alias. Aliases are often used when a self-join is performed, which means using the same table several times in the FROM clause.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset