0% found this document useful (0 votes)
41 views1 page

FROM Clause: Chapter 3: Selecting

The document discusses the FROM clause in SQL queries. It explains that the FROM clause specifies a virtual table or candidate result set that the other clauses like SELECT, WHERE operate on. It provides the syntax for the FROM clause and describes that it contains a comma separated list of table expressions which can include nested table expressions, subqueries, and lists of table expressions in brackets. It also describes different types of table terms that can be used in the FROM clause like table references, view references, derived tables and more.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views1 page

FROM Clause: Chapter 3: Selecting

The document discusses the FROM clause in SQL queries. It explains that the FROM clause specifies a virtual table or candidate result set that the other clauses like SELECT, WHERE operate on. It provides the syntax for the FROM clause and describes that it contains a comma separated list of table expressions which can include nested table expressions, subqueries, and lists of table expressions in brackets. It also describes different types of table terms that can be used in the FROM clause like table references, view references, derived tables and more.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

80 Chapter 3: Selecting

SELECT DISTINCT
TOP 4 START AT 2
t1.key_1 * 100 AS a,
t3.key_1 * 1000 AS b,
COUNT(*) AS c,
SUM ( t3.non_key_1 ) AS d
INTO #t
FROM ( t1 LEFT OUTER JOIN t2 ON t1.key_1 = t2.key_1 )
CROSS JOIN t3
WHERE b <= 5000
AND t3.non_key_1 = 333
GROUP BY ROLLUP ( t1.key_1, t3.key_1 )
HAVING COUNT(*) > 1
ORDER BY 1, 2
FOR XML AUTO;
This book doesnt go into the details of XML processing. However, here is what
the single column in the single row in the temporary #t looks like, wrapped to fit
the page:
<t1 a="100"><t3 c="2" d="666"/></t1><t1 a="200"><t3 c="6" d="1998"/><t3 b="3000"
c="3" d="999"/><t3 b="4000" c="3" d="999"/></t1>'
For more information about the SELECT INTO method of creating a temporary
table, see Section 1.15.2.3, SELECT INTO #table_name.

3.3 FROM Clause


Logically speaking, the FROM clause specifies a virtual table or candidate
result set on which all the other clauses operate. Once upon a time the FROM
clause was just a simple list of table names, but no more; modern advances have
added complex table expressions with nested operations and boolean expres-
sions that once were found only in the WHERE clause.
Here is the basic syntax for the FROM clause:
<from_clause> ::= FROM <table_specification>
<table_specification> ::= <table_expression_list>
<table_expression_list> ::= <table_expression>
{ "," <table_expression> } -- avoid the comma
The FROM clause consists of a comma-separated list of table expressions,
which in turn may consist of nested table expressions, subqueries, and even lists
of table expressions inside brackets:
<table_expression> ::= <table_term>
| <table_expression>
CROSS JOIN
<table_term>
| <table_expression>
[ <on_condition_shorthand> ] -- do not use
<join_operator>
<table_term>
[ <on_condition> ] -- use this instead
<table_term> ::= <table_reference>
| <view_reference>
| <derived_table>
| <procedure_reference>
| "(" <table_expression_list> ")"
| <lateral_derived_table>
<on_condition_shorthand> ::= KEY -- foreign key columns; do not use
| NATURAL -- like-named columns; do not use

You might also like