<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 (3)</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" >h1. From Clause Hints <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">From clause hints are typically specified in a comment block preceding the affected clause.  If multiple hints apply to that clause, the hints should be placed in the same comment block. <br> <br>{code:lang=SQL|title=Example Hint} <br>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 <br>{code} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Dependent Joins <br> <br>MAKEIND, MAKEDEP, and MAKENOTDEP are hints used to control [dependent join|Federated Optimizations#Dependent Joins] 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. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">* MAKEIND - treat this clause as the independent (feeder) side of a dependent join if possible. <br>* MAKEDEP - treat this clause as the dependent (filtered) side of a dependent join if possible. <br>* MAKENOTDEP - do not treat this clause as the dependent (filtered) side of a join. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Other Hints <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:lang=SQL|title=Example PRESERVE Hint} <br></td></tr>
            <tr><td class="diff-changed-lines" >FROM /*+ <span class="diff-changed-words">PRESERVE<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">R</span></span> */ (tbl1 inner join tbl2 inner join tbl3 on tbl2.col1 = tbl3.col1 on tbl1.col1 = tbl2.col1) <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <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/Subqueries#Subqueries-OptionalJoin">/*&#43; optional &#42;/</a> table2 ON join-criteria</li>
</ul>


<ul>
        <li>FROM <a href="#FROMClause-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.  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.</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-TEXTTABLE"></a>TEXTTABLE</h1>

<p>The TEXTTABLE function processes character input to produce tabular ouptut.  It supports both fixed and delimited file format parsing. The function itself defines what columns it projects. The TEXTTABLE function is implicitly a nested table and may be correlated to preceding FROM clause entries.</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;">TEXTTABLE(expression [SELECTOR string] COLUMNS &lt;COLUMN&gt;, ... [NO ROW DELIMITER] [DELIMITER char] [(QUOTE|ESCAPE) char] [HEADER [integer]] [SKIP integer]) AS name</pre>
</div></div>

<p>Where &lt;COLUMN&gt;</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;">COLUMN := name datatype [WIDTH integer [NO TRIM]] [SELECTOR string integer]</pre>
</div></div>

<p>Parameters</p>

<ul>
        <li>expression - the text content to process, which should be convertible to CLOB.</li>
</ul>


<ul>
        <li>SELECTOR specifies that delemited lines should only match if the line begins with the selector string followed by a delimiter. The selector value is a valid column value.  If a TEXTTABLE SELECTOR is specified, a SELECTOR may also be specified for column values.  A column SELECTOR argument will select the nearest preceding text line with the given SELECTOR prefix and select the value at the given 1-based integer position (which includes the selector itself). If no such text line or position with a given line exists, a null value will be produced.</li>
</ul>


<ul>
        <li>NO ROW DELIMITER indicates that fixed parsing should not assume the presence of newline row delimiters.</li>
</ul>


<ul>
        <li>DELIMITER sets the field delimiter character to use.  Defaults to ','.</li>
</ul>


<ul>
        <li>QUOTE sets the quote, or qualifier, character used to wrap field values.  Defaults to '"'.</li>
</ul>


<ul>
        <li>ESCAPE sets the escape character to use if no quoting character is in use. This is used in situations where the delimiter or new line characters are escaped with a preceding character, e.g. \,</li>
</ul>


<ul>
        <li>HEADER specifies the text line number (counting every new line) on which the column names occur.  All lines prior to the header will be skipped. If HEADER is specified, then the header line will be used to determine the TEXTTABLE column position by case-insensitive name matching.  This is especially useful in situations where only a subset of the columns are needed. If the HEADER value is not specified, it defaults to 1. If HEADER is not specified, then columns are expected to match positionally with the text contents.</li>
</ul>


<ul>
        <li>SKIP specifies the number of text lines (counting every new line) to skip before parsing the contents.  HEADER may still be specified with SKP.</li>
</ul>


<ul>
        <li>WIDTH indicates the fixed-width length of a column in characters - not bytes.  The CR NL newline value counts as a single character.</li>
</ul>


<ul>
        <li>NO TRIM specifies that the text value should not be trimmed of all leading and trailing white space.<br/>
Syntax Rules:</li>
</ul>


<ul>
        <li>If width is specified for one column it must be specified for all columns and be a non-negative integer.</li>
</ul>


<ul>
        <li>If width is specified, then fixed width parsing is used and ESCAPE, QUOTE, SELECTOR, and HEADER should not be specified.</li>
</ul>


<ul>
        <li>If width is not specified, then NO ROW DELIMITER cannot be used.</li>
</ul>


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


<p>Examples</p>

<ul>
        <li>Use of the HEADER parameter, returns 1 row ['b']:
<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 TEXTTABLE(UNESCAPE('col1,col2,col3\na,b,c') COLUMNS col2 string HEADER) x</pre>
</div></div></li>
</ul>


<ul>
        <li>Use of fixed width, returns 2 rows ['a', 'b', 'c'], ['d', 'e', 'f']:
<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 TEXTTABLE(UNESCAPE('abc\ndef') COLUMNS col1 string width 1, col2 string width 1, col3 string width 1) x</pre>
</div></div></li>
</ul>


<ul>
        <li>Use of fixed width without a row delimiter, returns 3 rows ['a'], ['b'], ['c']: <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 TEXTTABLE('abc' COLUMNS col1 string width 1 NO ROW DELIMITER) x</pre>
</div></div></li>
</ul>


<ul>
        <li>Use of ESCAPE parameter, returns 1 row ['a,', 'b']:
<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 TEXTTABLE('a:,,b' COLUMNS col1 string, col2 string ESCAPE ':') x</pre>
</div></div></li>
</ul>


<ul>
        <li>As a nested table:
<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, TEXTTABLE(t.clobcolumn COLUMNS first string, second date SKIP 1) x</pre>
</div></div></li>
</ul>


<ul>
        <li>Use of SELECTORs, returns 2 rows ['c', 'd', 'b'], ['c', 'f', 'b']:
<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 TEXTTABLE('a,b\nc,d\nc,f' SELECTOR 'c' COLUMNS col1 string, col2 string col3 string SELECTOR 'a' 2) x</pre>
</div></div></li>
</ul>



<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 be 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>


<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>
    </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=9&originalVersion=8">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>