Tables Are Just One of the Things You Can Put in a FROM Clause

From WikiContent

Revision as of 16:18, 22 January 2010 by Albeau (Talk | contribs)
Jump to: navigation, search

If you were to read a definition of the FROM clause in many of the introductory SQL books, you might see something like the following:

The FROM clause identifies one or more tables from which data is to be retrieved

While this is certainly true and covers a large percentage of use cases, it is far from being a comprehensive definition. Depending on which database server you are using, the elements referenced in your FROM clause may be of any of the following types:

  • Tables
  • Views
  • Subqueries
  • Files
  • XML Documents
  • Functions

Did you know that you can write a query that will open and read data from a file on the server? Or interact with the results of another query as if it were a table? Or, my personal favorite, process the results of a function call which returns a result set? If not, then you owe it to yourself to find out all the ways in which your database server can interact with various sources, whether they are managed locally or remotely.

Therefore, a far better definition of the FROM clause would be:

The FROM clause identifies one or more data sources from which data is to be retrieved

Using this definition, you can do far more intesting things than what is shown in most introductory SQL books.

Personal tools