Skip to main content
Blog

Demystifying the FROM Clause in SQL: Table Selection and Joining

The SQL FROM clause names the table a query reads. Run live examples of selecting from a table, relating two tables, and see how joins and table aliases fit in.

· Dev3lop Team

Every SELECT needs to know where to get its data — and that’s the FROM clause’s job. It names the table (or tables) the query reads. Simple as it sounds, FROM is also where SQL’s real power lives: it’s where you bring multiple tables together to answer questions no single table can.

The playground runs a real SQL engine in your browser. Change the table after FROM and watch the data change.

Try it — change the table

Selecting from a single table

The basic form names one table:

SELECT name, city
FROM customers;

FROM customers tells the database to read the customers table; the SELECT list picks which columns come back. This sample database has three tables — customers, products, and orders — and you can point FROM at any of them (open the Sample tables panel in any playground to see their columns).

Relating two tables

A single table only tells part of the story. The orders table records which customer placed each order via a customer_id, but the customer’s name and city live in customers. To answer “what did customers in London order?”, you need both tables working together.

The most approachable way to relate two tables is a subquery — one query feeding another. Here, the inner query finds London customers’ IDs, and the outer query pulls their orders:

SELECT product, amount
FROM orders
WHERE customer_id IN (
  SELECT id FROM customers WHERE city = 'London'
);

Bringing two tables together

Joining tables (the fuller tool)

Subqueries are great for “filter this table by that table.” When you want columns from both tables in one result — each order alongside its customer’s name and city — you use a JOIN, still inside the FROM clause:

SELECT orders.product, customers.name, customers.city
FROM orders
JOIN customers ON orders.customer_id = customers.id;

The ON clause says how the rows line up — here, matching orders.customer_id to customers.id. The main join types:

  • INNER JOIN — only rows with a match in both tables.
  • LEFT JOIN — every row from the left table, plus matches from the right (nulls where there’s no match).
  • RIGHT JOIN / FULL JOIN — the mirror image, and both-sides-everything.

Run a real join right here — each order shown alongside the name and city of the customer who placed it:

A live JOIN

Joins are a big topic with their own guides — SQL joins demystified for the basics and SQL join types for INNER vs LEFT vs RIGHT vs FULL.

Table aliases

When a query names more than one table, aliases give each a short handle so you can qualify columns without repeating long names:

SELECT o.product, c.name
FROM orders AS o
JOIN customers AS c ON o.customer_id = c.id;

orders AS o (the AS is optional) lets you write o.product instead of orders.product. Aliases are also what make a self-join possible — joining a table to itself, e.g. employees to their managers — by giving the same table two different names.

Practice

Your turn

Using the orders table, return the product and amount of every order placed by a customer located in London. Use a subquery against the customers table.

Frequently asked questions

What is the FROM clause in SQL? It specifies the table (or tables) a query reads from. It follows the SELECT list: SELECT columns FROM table.

Can a query read from more than one table? Yes — that’s what JOIN (and subqueries) are for. You list the tables in FROM and describe how their rows relate with an ON condition.

What is a table alias? A short name for a table within a query — FROM orders AS o lets you write o.product. Aliases keep multi-table queries readable and enable self-joins.

What’s the difference between a JOIN and a subquery? A subquery uses one table’s results to filter another; a JOIN combines columns from multiple tables into a single result row. Use a join when you need columns from the other table, not just a membership test.

From selecting to shaping

FROM is where a query decides which data it’s built on. When “which data” spans many systems — a CSV here, a Postgres table there, an API somewhere else — ET1 makes each source an input node on a visual canvas, and combining them a drag-and-drop Joiner, with a live preview at every step.

Next: pick your columns with SELECT, filter rows with WHERE, or go deep on combining tables in the joins guide.