SQL Keywords

SQL FROM

What is the SQL FROM clause?

The FROM clause specifies the table, view, or subquery that a query will read rows from.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL FROM: Supported by PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, Redshift, BigQuery, and all ANSI-compliant databases.

SQL FROM Full Explanation

The SQL FROM clause is the backbone of any data-retrieval query. It tells the database which table, view, or derived table (subquery or common table expression) is the initial source of rows. The query planner builds the rest of the execution plan around this clause, applying joins, filters, grouping, and projections only after determining where the data comes from.A single query can list multiple table references in the FROM clause, either separated by commas (legacy syntax) or connected with explicit JOIN operators. Modern best practice favors explicit JOINs because they make join conditions, join order, and join types clear. The FROM clause accepts:- Base tables and views- Aliased tables for shorter or clearer column references- Inline subqueries wrapped in parentheses and optionally aliased- Common table expressions (via WITH) that act like temporary views- Table functions or set-returning functions, depending on dialectExecution order is logical, not physical: the FROM clause is processed before WHERE, GROUP BY, HAVING, or SELECT projections. Misunderstanding this order can lead to unexpected results or performance issues. Caveats:1. Omitting required join predicates can create a Cartesian product.2. Comma-separated tables implicitly create CROSS JOINs that may harm performance.3. Some dialects (SQLite) require parentheses around joined subqueries.4. ANSI SQL forbids columns in SELECT that are not aggregated or grouped unless they originate from the GROUP BY source, but many databases relax this rule.5. Read privileges on the referenced objects are mandatory; otherwise, the query fails with a permission error.

SQL FROM Syntax

SELECT column_list
FROM table_reference [AS alias]
     [JOIN table_reference ON join_condition]
     [... additional JOIN clauses ...];

SQL FROM Parameters

  • - table_reference (identifier | subquery) - Base table, view, or derived table to read from
  • - alias (identifier, optional) - Alternate name for the table reference
  • - join_condition (boolean expression, optional) - Predicate that defines how rows from two sources are matched

Example Queries Using SQL FROM

-- 1. Basic single table
SELECT id, name
FROM customers;

-- 2. Explicit inner join
SELECT o.id, c.name, o.total
FROM orders AS o
JOIN customers AS c ON c.id = o.customer_id;

-- 3. Subquery in FROM
SELECT sub.region, COUNT(*) AS user_cnt
FROM (
  SELECT region, id
  FROM users
  WHERE signup_date >= CURRENT_DATE - INTERVAL '30 days'
) AS sub
GROUP BY sub.region;

-- 4. Multiple joins with aliases
SELECT p.name, c.category_name, s.name AS supplier
FROM products p
LEFT JOIN categories c ON c.id = p.category_id
INNER JOIN suppliers s ON s.id = p.supplier_id;

Expected Output Using SQL FROM

  • Each query returns a result set composed only of rows found in the tables or subqueries named in the FROM clause, filtered and joined according to additional clauses

Use Cases with SQL FROM

  • Selecting data from one or more tables for reporting
  • Building complex analytical queries that combine fact and dimension tables
  • Joining reference data for enrichment
  • Aggregating results derived from a subquery
  • Creating views or materialized views by defining their FROM source

Common Mistakes with SQL FROM

  • Forgetting a JOIN predicate, leading to a Cartesian product
  • Using comma joins instead of explicit JOIN syntax
  • Omitting table aliases and creating ambiguous column references
  • Misspelling an alias in the SELECT list
  • Expecting WHERE to execute before FROM and JOINs
  • Lacking SELECT permission on the referenced object

Related Topics

SELECT, WHERE, JOIN, INNER JOIN, LEFT JOIN, CROSS JOIN, WITH (CTE), GROUP BY

First Introduced In

SQL-86 (ANSI SQL-1)

Frequently Asked Questions

What is the purpose of the FROM clause?

It defines the source tables, views, or subqueries that the query will read data from.

Can I query multiple tables in one FROM clause?

Absolutely. Use explicit JOIN syntax to connect them and specify the join condition.

Do I need an alias for every table?

Aliases are optional but strongly recommended when the query involves more than one table or a subquery to avoid ambiguity.

What happens if I forget the JOIN condition?

The database creates a Cartesian product between the tables, which usually returns far more rows than expected and hurts performance.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!