FROM
The FROM
clause specifies the data source for your query, indicating which view table to retrieve data from. In multi-table views, it establishes the primary source table that can be joined with other tables.
Elements
table_name
-
The name of the view table to query. This corresponds to a
TableUpdater
defined in your View. Table names can be specified with the@Table
annotation or can be automatically derived for single table views.
Features
- Table selection
-
Specifies the primary source table for the query. This table contains the rows that will be examined by the query.
- Derived tables
-
In advanced scenarios, a subquery can be used in place of a table name to create a derived table.
Table names
Table names in a View query correspond to the name specified in the @Table
annotation on a TableUpdater
class. Single table views may omit the @Table
annotation.
Examples
SELECT * FROM customers
@Table("customer_profiles")
SELECT * FROM customer_profiles
SELECT customers.name, orders.id
FROM customers
JOIN orders ON orders.customerId = customers.id
SELECT * FROM (
SELECT name, address
FROM customers
WHERE active = true
) AS active_customers
Notes
-
The
FROM
clause is required in every query -
Table names are case-sensitive
-
When using joins, the first table in the FROM clause becomes the left side of the first join
-
Table names must correspond to
TableUpdater
classes defined in your View -
If table names contain special characters or spaces, they must be enclosed in backticks
Related Features
-
SELECT clause - Specifies what data to retrieve
-
JOIN clause - Combines data from multiple tables
-
WHERE clause - Filters results based on conditions
-
Table updaters - Defining view tables in code