<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/FROM+Clause">FROM Clause</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~shawkins">Steven Hawkins</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>* MAKEIND - treat this clause as the independent (feeder) side of a dependent join if possible. <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">* MAKEDEP - treat this clause as the dependent (filtered) side of a dependent join if possible.  MAKEDEP as a non-comment hint supports optional max and join arguments - MAKEDEP(JOIN) meaning that the entire join should be pushed, and MAKEDEP(MAX:5000) meaning that the dependent join should only be performed if there are less than the max number of values from the independent side. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">* MAKEDEP - treat this clause as the dependent (filtered) side of a dependent join if possible.  MAKEDEP and MAKEIND support optional max and join arguments: <br>** MAKEDEP(JOIN) means that the entire join should be pushed <br>** MAKEDEP(NO JOIN) means that the entire join should not be pushed <br>** MAKEDEP(MAX:val) meaning that the dependent join should only be performed if there are less than the max number of values from the independent side. <br></td></tr>
            <tr><td class="diff-unchanged" >* MAKENOTDEP - do not treat this clause as the dependent (filtered) side of a join. <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>The FROM clause specifies the target table(s) for SELECT, UPDATE, and DELETE statements.</p>

<p>Example Syntax:</p>

<ul>
        <li>FROM table [[AS] alias]</li>
</ul>


<ul>
        <li>FROM table1 [INNER&#124;LEFT OUTER&#124;RIGHT OUTER&#124;FULL OUTER] JOIN table2 ON join-criteria</li>
</ul>


<ul>
        <li>FROM table1 CROSS JOIN table2</li>
</ul>


<ul>
        <li>FROM (subquery) [AS] alias</li>
</ul>


<ul>
        <li>FROM <a href="#FROMClause-NestedTableReference">TABLE(subquery)</a> [AS] alias</li>
</ul>


<ul>
        <li>FROM table1 JOIN /*&#43; MAKEDEP &#42;/ table2 ON join-criteria</li>
</ul>


<ul>
        <li>FROM table1 JOIN /*&#43; MAKENOTDEP &#42;/ table2 ON join-criteria</li>
</ul>


<ul>
        <li>FROM /*&#43; MAKEIND &#42;/ table1 JOIN table2 ON join-criteria</li>
</ul>


<ul>
        <li>FROM /*&#43; NO_UNNEST &#42;/ vw1 JOIN table2 ON join-criteria</li>
</ul>


<ul>
        <li>FROM table1 left outer join <a href="/author/display/TEIID/Federated+Optimizations#FederatedOptimizations-OptionalJoin">/*&#43; optional &#42;/</a> table2 ON join-criteria</li>
</ul>


<ul>
        <li>FROM <a href="/author/display/TEIID/TEXTTABLE" title="TEXTTABLE">TEXTTABLE...</a></li>
</ul>


<ul>
        <li>FROM <a href="#FROMClause-XMLTABLE">XMLTABLE...</a></li>
</ul>


<ul>
        <li>FROM <a href="/author/display/TEIID/ARRAYTABLE" title="ARRAYTABLE">ARRAYTABLE...</a></li>
</ul>


<ul>
        <li>FROM <a href="/author/display/TEIID/OBJECTTABLE" title="OBJECTTABLE">OBJECTTABLE...</a></li>
</ul>


<ul>
        <li>FROM (<a href="/author/display/TEIID/Subqueries#Subqueries-Inlineviews">SELECT ...</a></li>
</ul>


<h1><a name="FROMClause-FromClauseHints"></a>From Clause Hints</h1>

<p>From clause hints are typically specified in a comment block preceding the affected clause.  MAKEDEP and MAKENOTDEP may also appear after in non-comment form after the affected clause.  If multiple hints apply to that clause, the hints should be placed in the same comment block.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example Hint</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
FROM /*+ MAKEDEP PRESERVE */ (tbl1 inner join tbl2 inner join tbl3 on tbl2.col1 = tbl3.col1 on tbl1.col1 = tbl2.col1), tbl3 WHERE tbl1.col1 = tbl2.col1
</pre>
</div></div>

<h3><a name="FROMClause-DependentJoins"></a>Dependent Joins</h3>

<p>MAKEIND, MAKEDEP, and MAKENOTDEP are hints used to control <a href="/author/display/TEIID/Federated+Optimizations#FederatedOptimizations-DependentJoins">dependent join</a> behavior. They should only be used in situations where the optimizer does not choose the most optimal plan based upon query structure, metadata, and costing information.  The hints may appear in a comment that proceeds the from clause. The hints can be specified against any from clause, not just a named table.</p>

<ul>
        <li>MAKEIND - treat this clause as the independent (feeder) side of a dependent join if possible.</li>
        <li>MAKEDEP - treat this clause as the dependent (filtered) side of a dependent join if possible.  MAKEDEP and MAKEIND support optional max and join arguments:
        <ul>
                <li>MAKEDEP(JOIN) means that the entire join should be pushed</li>
                <li>MAKEDEP(NO JOIN) means that the entire join should not be pushed</li>
                <li>MAKEDEP(MAX:val) meaning that the dependent join should only be performed if there are less than the max number of values from the independent side.</li>
        </ul>
        </li>
        <li>MAKENOTDEP - do not treat this clause as the dependent (filtered) side of a join.</li>
</ul>


<h3><a name="FROMClause-OtherHints"></a>Other Hints</h3>

<p>NO_UNNEST can be specified against a subquery from clause or view to instruct the planner to not merge the nested SQL in the surrounding query - also known as view flattening.  This hint only applies to Teiid planning and is not passed to source queries.  NO_UNNEST may appear in a comment that proceeds the from clause.</p>

<p>The PRESERVE hint can be used against an ANSI join tree to preserve the structure of the join rather than allowing the Teiid optimizer to reorder the join.  This is similar in function to the Oracle ORDERED or MySQL STRAIGHT_JOIN hints.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example PRESERVE Hint</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
FROM /*+ PRESERVE */ (tbl1 inner join tbl2 inner join tbl3 on tbl2.col1 = tbl3.col1 on tbl1.col1 = tbl2.col1)
</pre>
</div></div>

<h1><a name="FROMClause-NestedTableReference"></a>Nested Table Reference</h1>

<p>Nested tables may appear in the FROM clause with the TABLE keyword. They are an alternative to using a view with normal join semantics.  The columns projected from the command contained in the nested table may be used just as any of the other FROM clause projected columns in join criteria, the where clause, etc.</p>

<p>A nested table may have correlated references to preceding FROM clause column references as long as INNER and LEFT OUTER joins are used. This is especially useful in cases where then nested expression is a procedure or function call.</p>

<p>Valid example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">select * from t1, TABLE(call proc(t1.x)) t2</pre>
</div></div>

<p>Invalid example, since t1 appears after the nested table in the from clause:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">select * from TABLE(call proc(t1.x)) t2, t1</pre>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Multiple Execution</b><br />The usage of a correlated nested table may result in multiple executions of the table expression - once for each correlated row.</td></tr></table></div>

<h1><a name="FROMClause-XMLTABLE"></a>XMLTABLE</h1>

<p>The XMLTABLE function uses XQuery to produce tabular ouput. The XMLTABLE function is implicitly a nested table and may be correlated to preceding FROM clause entries.  XMLTABLE is part of the SQL/XML 2006 specification.</p>

<p>Usage:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">XMLTABLE([&lt;NSP&gt;,] xquery-expression [&lt;PASSING&gt;] [COLUMNS &lt;COLUMN&gt;, ... )] AS name</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">COLUMN := name (FOR ORDINALITY | (datatype [DEFAULT expression] [PATH string]))</pre>
</div></div>

<p>See <a href="/author/display/TEIID/XML+Functions#XMLFunctions-XMLELEMENT">XMLELEMENT</a> for the definition of NSP - XMLNAMESPACES.</p>

<p>See <a href="/author/display/TEIID/XML+Functions#XMLFunctions-XMLQUERY">XMLQUERY</a> for the definition of PASSING.</p>

<p>See also <a href="/author/display/TEIID/XML+Functions#XMLFunctions-XMLQUERY">XMLQUERY</a></p>


<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>See also <a href="/author/display/TEIID/XQuery+Optimization" title="XQuery Optimization">XQuery Optimization</a></td></tr></table></div>

<p>Parameters</p>

<ul>
        <li>The optional XMLNAMESPACES clause specifies the namepaces for use in the XQuery and COLUMN path expressions.</li>
</ul>


<ul>
        <li>The xquery-expression should be a valid XQuery.  Each sequence item returned by the xquery will be used to create a row of values as defined by the COLUMNS clause.</li>
</ul>


<ul>
        <li>If COLUMNS is not specified, then that is the same as having the COLUMNS clause: "COLUMNS OBJECT_VALUE XML PATH '.'", which returns the entire item as an XML value.</li>
</ul>


<ul>
        <li>A FOR ORDINALITY column is typed as integer and will return the 1-based item number as its value.</li>
</ul>


<ul>
        <li>Each non-ordinality column specifies a type and optionally a PATH and a DEFAULT expression.</li>
</ul>


<ul>
        <li>If PATH is not specified, then the path will be the same as the column name.<br/>
Syntax Rules:</li>
</ul>


<ul>
        <li>Only 1 FOR ORDINALITY column may be specified.</li>
</ul>


<ul>
        <li>The columns names must not contain duplicates.</li>
</ul>


<ul>
        <li>The blob datatype is supported, but there is only built-in support for xs:hexBinary values.&nbsp; For xs:base64Binary, use a workaround of a PATH that uses the explicit value constructor "xs:base64Binary(&lt;path&gt;)".</li>
</ul>


<ul>
        <li>The column expression must evaluate to a single value if a non-array type is expected.</li>
</ul>


<p>Examples</p>

<p>Use of passing, returns 1 row [1]:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">select * from xmltable('/a' PASSING xmlparse(document '&lt;a id="1"/&gt;') COLUMNS id integer PATH '@id') x</pre>
</div></div>

<p>As a nested table:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">select x.* from t, xmltable('/x/y' PASSING t.doc COLUMNS first string, second FOR ORDINALITY) x</pre>
</div></div>

<p>Invalid multi-value:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">select * from xmltable('/a' PASSING xmlparse(document '&lt;a&gt;&lt;b id="1"/&gt;&lt;b id="2"/&gt;&lt;/a&gt;') COLUMNS id integer PATH 'b/@id') x</pre>
</div></div>

<p>Array multi-value:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">select * from xmltable('/a' PASSING xmlparse(document '&lt;a&gt;&lt;b id="1"/&gt;&lt;b id="2"/&gt;&lt;/a&gt;') COLUMNS id integer[] PATH 'b/@id') x</pre>
</div></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/FROM+Clause">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=18646226&revisedVersion=22&originalVersion=21">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/FROM+Clause?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>