liveBook · Manning

From clause

As explained in Learn SQL in a Month of Lunches

A FROM clause is the SQL clause that specifies the table or other data source from which data is retrieved or related data is selected.

When you ask for data, the FROM clause tells SQL where to look. Think of a spreadsheet request: SELECT names FROM the vegetables sheet. In a query, SELECT names the data you want, while FROM identifies the table or other data set that supplies it. section 2.2 section 2.4

Choose a table before retrieving its column

To see every vegetable name, write: SELECT Name FROM vegetables; Name is the column to return. vegetables is the table to query. SELECT must come before FROM; reversing those clauses produces a syntax error. section 2.2 section 3.1.1

Figure 2.5 A vegetables table with two columns and five rows. We’re going to learn how to create a query that shows the names of all the vegetables.

Use this small table to distinguish the source table named after FROM from the column named after SELECT. section 2.2

The FROM clause remains the place where a query identifies its data source, including these nearby uses:

  • In a multi-table query, FROM is where the data set is identified and tables are joined through JOIN conditions. section 8.2 section 13.2
  • A date-range variable can appear in a JOIN condition attached to a table in the FROM clause, although WHERE is the more typical location for filtering. section 13.2
  • DELETE statements can use FROM to name the table whose rows will be deleted; retaining the keyword helps portability because some RDBMSes permit its omission. section 17.2.1

A basic retrieval query needs both SELECT and FROM: one states what to return, and the other states where to find it. Keep their order fixed, and finish the statement with a semicolon. section 2.4 section 3.1.1

How Learn SQL in a Month of Lunches covers it

How deep it goes
Defines FROM, demonstrates a one-table query, and notes clause order, joins, variables, and DELETE portability.
Examples
Uses a vegetables table, customer-order date filtering, title-sales thresholds, and deletion by TitleID.
What it assumes
Teaches table, column, row, value, query, SELECT, and FROM vocabulary from introductory examples.
What you can do after
Apply it to name a query's source table, join related tables, and retain portable DELETE syntax.
How it connects
Connects FROM with SELECT, tables, JOIN, WHERE, HAVING, variables, and DELETE.

Also explained in

Compare how 3 books explain from clause →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn SQL in a Month of Lunches. The section links point to the parts of the book it draws on.