FROM Clause Data Sources

The first logical component of a typical SQL SELECT statement is the FROM clause. In a simple SQL SELECT statement, the FROM clause contains a single table. However, the FROM clause can also combine data from multiple sources and multiple types of data sources. The maximum number of tables that may be accessed within a single SQL SELECT statement is 256.

The FROM clause is the foundation of the rest of the SQL statement. For a table column to be in the output, accessed in the WHERE conditions, or in the ORDER BY, it must be in the FROM clause.

Possible Data Sources

SQL is extremely flexible and can accept data from 10 distinctly different types of data sources within the FROM clause:

  • Local SQL Server tables.
  • Subqueries serving as derived tables, also called subselects or in-line views (see Chapter 9). Common table expressions (CTEs) are functionally similar to subqueries but may be referenced multiple times within the query.
  • You can reference views or stored SELECT statements within the FROM clause as if they were tables. Chapter 11, “Projecting Data through Views,” discusses views.
  • Table-valued user-defined functions return rows and columns. See Chapter 18, “Building User- Defined Functions,” for more information.
  • Distributed data sources pull in data from other SQL Server databases, other SQL Servers, other database platforms (for example, Microsoft Access, Oracle, and Foxpro), or applications (for example, Excel) using openquery() and other distributed ...

Get Microsoft SQL Server 2012 Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.