<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – SELECT</title>
    <link>/en/sql-reference/statements/select/</link>
    <description>Recent content in SELECT on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/sql-reference/statements/select/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Sql-Reference: EXCEPT clause</title>
      <link>/en/sql-reference/statements/select/except-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/except-clause/</guid>
      <description>
        
        
        &lt;p&gt;Combines two or more SELECT queries. EXCEPT returns distinct results of the left-hand query that are not also found in the right-hand query.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

MINUS is an alias for EXCEPT.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT
    EXCEPT &lt;span class=&#34;code-variable&#34;&gt;except-query&lt;/span&gt;[...]
    [ &lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/#&#34;&gt;ORDER BY&lt;/a&gt; { &lt;span class=&#34;code-variable&#34;&gt;column-name&lt;/span&gt;  | &lt;span class=&#34;code-variable&#34;&gt;ordinal-number&lt;/span&gt; } [ ASC | DESC ] [,...] ]
    [ &lt;a href=&#34;../../../../en/sql-reference/statements/select/limit-clause/#&#34;&gt;LIMIT&lt;/a&gt; { &lt;span class=&#34;code-variable&#34;&gt;integer&lt;/span&gt; | ALL } ]
    [ &lt;a href=&#34;../../../../en/sql-reference/statements/select/offset-clause/#&#34;&gt;OFFSET&lt;/a&gt; &lt;span class=&#34;code-variable&#34;&gt;integer&lt;/span&gt; ]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;notes&#34;&gt;Notes&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use the EXCEPT clause to filter out specific results from a SELECT statement. The EXCEPT query operates on the results of two or more SELECT queries. It returns only those rows in the left-hand query that are not also present in the right-hand query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;OpenText™ Analytics Database evaluates multiple EXCEPT clauses in the same SELECT query from left to right, unless parentheses indicate otherwise.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You cannot use the ALL keyword with an EXCEPT query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The results of each SELECT statement must be union compatible. Each statement must return the same number of columns, and the corresponding columns must have compatible data types. For example, you cannot use the EXCEPT clause on a column of type INTEGER and a column of type VARCHAR. If statements do not meet these criteria, the database returns an error.&lt;/p&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The &lt;a href=&#34;../../../../en/sql-reference/data-types/data-type-coercion-chart/#&#34;&gt;Data type coercion chart&lt;/a&gt; lists the data types that can be cast to other data types. If one data type can be cast to the other, those two data types are compatible.

&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can use EXCEPT in FROM, WHERE, and HAVING clauses.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can order the results of an EXCEPT operation by including an ORDER BY operation in the statement. When you write the ORDER BY list, specify the column names from the leftmost SELECT statement, or specify integers that indicate the position of the columns by which to sort.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The rightmost ORDER BY, LIMIT, or OFFSET clauses in an EXCEPT query do not need to be enclosed in parentheses, because the rightmost query specifies that the database perform the operation on the results of the EXCEPT operation. Any ORDER BY, LIMIT, or OFFSET clauses contained in SELECT queries that appear earlier in the EXCEPT query must be enclosed in parentheses.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The database supports EXCEPT &lt;a href=&#34;../../../../en/data-analysis/queries/subqueries/noncorrelated-and-correlated-subqueries/&#34;&gt;noncorrelated subquery&lt;/a&gt; predicates. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM T1
   WHERE T1.x IN
      (SELECT MAX(c1) FROM T2
       &lt;span class=&#34;code-input&#34;&gt;EXCEPT&lt;/span&gt;
          SELECT MAX(cc1) FROM T3
       &lt;span class=&#34;code-input&#34;&gt;EXCEPT &lt;/span&gt;
          SELECT MAX(d1) FROM T4);
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Consider the following three tables:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Company_A&lt;/strong&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  Id  | emp_lname |      dept      | sales
------+-----------+----------------+-------
 1234 | Stephen   | auto parts     |  1000
 5678 | Alice     | auto parts     |  2500
 9012 | Katherine | floral         |   500
 3214 | Smithson  | sporting goods |  1500
(4 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Company_B&lt;/strong&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  Id  | emp_lname |    dept     | sales
------+-----------+-------------+-------
 4321 | Marvin    | home goods  |   250
 8765 | Bob       | electronics | 20000
 9012 | Katherine | home goods  |   500
 3214 | Smithson  | home goods  |  1500
(4 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Company_C&lt;/strong&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  Id  | emp_lname |      dept      | sales
------+-----------+----------------+-------
 3214 | Smithson  | sporting goods |  1500
 5432 | Madison   | sporting goods |   400
 7865 | Cleveland | outdoor        |  1500
 1234 | Stephen   | floral         |  1000
(4 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query returns the IDs and last names of employees that exist in Company_A, but not in Company_B:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_lname FROM Company_A
   EXCEPT
   SELECT id, emp_lname FROM Company_B;
  id  | emp_lname
------+-----------
 1234 | Stephen
 5678 | Alice
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query sorts the results of the previous query by employee last name:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_lname FROM Company_A
   EXCEPT
   SELECT id, emp_lname FROM Company_B
   &lt;span class=&#34;code-input&#34;&gt;ORDER BY&lt;/span&gt; emp_lname ASC;
  id  | emp_lname
------+-----------
 5678 | Alice
 1234 | Stephen
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you order by the column position, the query returns the same results:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_lname FROM Company_A
   EXCEPT
   SELECT id, emp_lname FROM Company_B
   &lt;span class=&#34;code-input&#34;&gt;ORDER BY 2 &lt;/span&gt;ASC;
  id  | emp_lname
------+-----------
 5678 | Alice
 1234 | Stephen
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query returns the IDs and last names of employees that exist in Company_A, but not in Company_B or Company_C:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_lname FROM Company_A
   EXCEPT
   SELECT id, emp_lname FROM Company_B
   EXCEPT
   SELECT id, emp_lname FROM Company_C;
  id  | emp_lname
------+-----------
 5678 | Alice
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query shows the results of mismatched data types:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_lname FROM Company_A
   EXCEPT
   SELECT emp_lname, id FROM Company_B;
ERROR 3429:  For &amp;#39;EXCEPT&amp;#39;, types int and varchar are inconsistent
DETAIL:  Columns: id and emp_lname
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using the &lt;a href=&#34;../../../../en/getting-started/introducing-vmart-example-db/&#34;&gt;VMart&lt;/a&gt; example database, the following query returns information about all Connecticut-based customers who bought items through stores and whose purchases amounted to more than $500, except for those customers who paid cash:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_key, customer_name FROM public.customer_dimension
      WHERE customer_key IN (SELECT customer_key FROM store.store_sales_fact
         WHERE sales_dollar_amount &amp;gt; 500
         EXCEPT
         SELECT customer_key FROM store.store_sales_fact
         WHERE tender_type = &amp;#39;Cash&amp;#39;)
      AND customer_state = &amp;#39;CT&amp;#39;;
 customer_key |    customer_name
--------------+----------------------
        15084 | Doug V. Lampert
        21730 | Juanita F. Peterson
        24412 | Mary U. Garnett
        25840 | Ben Z. Taylor
        29940 | Brian B. Dobisz
        32225 | Ruth T. McNulty
        33127 | Darlene Y. Rodriguez
        40000 | Steve L. Lewis
        44383 | Amy G. Jones
        46495 | Kevin H. Taylor
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/#&#34;&gt;SELECT&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/intersect-clause/#&#34;&gt;INTERSECT clause&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/union-clause/#&#34;&gt;UNION clause&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/queries/subqueries/#&#34;&gt;Subqueries&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: FROM clause</title>
      <link>/en/sql-reference/statements/select/from-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/from-clause/</guid>
      <description>
        
        
        &lt;p&gt;A comma-separated list of data sources to query.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;FROM &lt;span class=&#34;code-variable&#34;&gt;dataset&lt;/span&gt;[,...] [ TABLESAMPLE(&lt;span class=&#34;code-variable&#34;&gt;percent&lt;/span&gt;) ]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;dataset&lt;/code&gt;&lt;/em&gt;``&lt;/dt&gt;
&lt;dd&gt;A set of data to query, one of the following:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/from-clause/table-reference/&#34;&gt;Table reference&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/from-clause/joined-table/&#34;&gt;Joined tables&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/data-analysis/views/&#34;&gt;View&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Named &lt;a href=&#34;../../../../en/data-analysis/queries/subqueries/&#34;&gt;subquery&lt;/a&gt;: &lt;em&gt;&lt;code&gt;subquery&lt;/code&gt;&lt;/em&gt;&lt;code&gt;[AS]&lt;/code&gt;&lt;em&gt;&lt;code&gt;name&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;dt&gt;
&lt;code&gt;`TABLESAMPLE(&lt;span class=&#34;code-variable&#34;&gt;percent&lt;/span&gt;)`&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies to return a random sampling of records, where &lt;em&gt;&lt;code&gt;percent&lt;/code&gt;&lt;/em&gt; specifies the approximate sampling size. The &lt;em&gt;&lt;code&gt;percent&lt;/code&gt;&lt;/em&gt; value must be between 0 and 100, exclusive, and can include decimal values. The number of records returned is not guaranteed to be the exact percentage specified.
&lt;p&gt;All rows of the data have equal opportunities to be selected. OpenText™ Analytics Database performs sampling before applying other query filters.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Count all records in &lt;code&gt;customer_dimension&lt;/code&gt; table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT COUNT(*) FROM customer_dimension;
 COUNT
-------
 50000
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Return a small sampling of rows in table &lt;code&gt;customer_dimension&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_name, customer_state FROM customer_dimension TABLESAMPLE(0.5) WHERE customer_state=&amp;#39;IL&amp;#39;;
    customer_name    | customer_state
---------------------+----------------
 Amy Y. McNulty      | IL
 Daniel C. Nguyen    | IL
 Midori O. Greenwood | IL
 Meghan U. Lampert   | IL
 Tiffany Y. Lang     | IL
 Laura S. King       | IL
 Steve T. Nguyen     | IL
 Craig S. Webber     | IL
 Luigi A. Lewis      | IL
 Mark W. Williams    | IL
(10 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: GROUP BY clause</title>
      <link>/en/sql-reference/statements/select/group-by-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/group-by-clause/</guid>
      <description>
        
        
        &lt;p&gt;Use the &lt;code&gt;GROUP BY&lt;/code&gt; clause with aggregate functions in a &lt;code&gt;SELECT&lt;/code&gt; statement to collect data across multiple records. OpenText™ Analytics Database groups the results into one or more sets of rows that match an expression.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;GROUP BY&lt;/code&gt; clause without aggregates is similar to using &lt;code&gt;SELECT DISTINCT&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/rollup-aggregate/#&#34;&gt;ROLLUP&lt;/a&gt;&lt;/code&gt; is an extension to the &lt;code&gt;GROUP BY&lt;/code&gt; clause. &lt;code&gt;ROLLUP&lt;/code&gt; performs subtotal aggregations.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;GROUP BY [/*+GBYTYPE(&lt;span class=&#34;code-variable&#34;&gt;algorithm&lt;/span&gt;)*/] { &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; | &lt;span class=&#34;code-variable&#34;&gt;aggregate-expression&lt;/span&gt; }[,...]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;
&lt;code&gt;/*+&lt;a href=&#34;../../../../en/sql-reference/language-elements/hints/gbytype/#&#34;&gt;GBYTYPE&lt;/a&gt;(&lt;span class=&#34;code-variable&#34;&gt;algorithm&lt;/span&gt;)*/&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies which algorithm has precedence for implementing this 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/#&#34;&gt;GROUP BY&lt;/a&gt;&lt;/code&gt; clause, over the algorithm the database query optimizer might otherwise choose. You can set &lt;em&gt;&lt;code&gt;algorithm&lt;/code&gt;&lt;/em&gt; to one of the following values:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;HASH&lt;/code&gt;: &lt;code&gt;GROUPBY HASH&lt;/code&gt; algorithm&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;PIPE&lt;/code&gt;: &lt;code&gt;GROUPBY PIPELINED&lt;/code&gt; algorithm&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information about both algorithms, see &lt;a href=&#34;../../../../en/data-analysis/query-optimization/group-by-queries/group-by-implementation-options/#&#34;&gt;GROUP BY implementation options&lt;/a&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any expression, including constants and column references in the tables specified in the &lt;a href=&#34;../../../../en/sql-reference/statements/select/from-clause/&#34;&gt;FROM clause&lt;/a&gt;. For example:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt;,... &lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt;, (&lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;aggregate-expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;An ordered list of columns, expressions, &lt;code&gt;CUBE, GROUPING SETS&lt;/code&gt;, or &lt;code&gt;ROLLUP&lt;/code&gt; aggregates.
&lt;p&gt;You can include &lt;code&gt;CUBE&lt;/code&gt; and &lt;code&gt;ROLLUP&lt;/code&gt; aggregates within a &lt;code&gt;GROUPING SETS&lt;/code&gt; aggregate. &lt;code&gt;CUBE&lt;/code&gt; and &lt;code&gt;ROLLUP&lt;/code&gt; aggregates can result in a large amount of output. In that case, use &lt;code&gt;GROUPING SETS&lt;/code&gt; to return only certain results.&lt;/p&gt;
&lt;p&gt;You cannot include any aggregates within a &lt;code&gt;CUBE&lt;/code&gt; or &lt;code&gt;ROLLUP&lt;/code&gt; expression.&lt;/p&gt;
&lt;p&gt;You can append multiple &lt;code&gt;GROUPING SETS&lt;/code&gt;, &lt;code&gt;CUBE&lt;/code&gt;, or &lt;code&gt;ROLLUP&lt;/code&gt; aggregates in the same query. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  
GROUP BY a,b,c,d, ROLLUP(a,b)
GROUP BY a,b,c,d, CUBE((a,b),c,d)
GROUP BY a,b,c,d, CUBE(a,b), ROLLUP (c,d)
GROUP BY ROLLUP(a), CUBE(b), GROUPING SETS(c)
GROUP BY a,b,c,d, GROUPING SETS ((a,d),(b,c),CUBE(a,b))
GROUP BY a,b,c,d, GROUPING SETS ((a,d),(b,c),(a,b),(a),(b),())
&lt;/code&gt;&lt;/pre&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;usage-considerations&#34;&gt;Usage considerations&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;expression&lt;/em&gt; cannot include &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/&#34;&gt;aggregate functions&lt;/a&gt;. However, you can use the GROUP BY clause with CUBE, GROUPING SETS, and &lt;code&gt;ROLLUP&lt;/code&gt; to return summary values for each group.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When you create a GROUP BY clause, you must include all non-aggregated columns that appear in the &lt;code&gt;SELECT&lt;/code&gt; list.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the &lt;code&gt;GROUP BY&lt;/code&gt; clause includes a &lt;code&gt;WHERE&lt;/code&gt; clause, the database ignores all rows that do not satisfy the &lt;code&gt;WHERE&lt;/code&gt; clause.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;This example shows how to use the &lt;code&gt;WHERE&lt;/code&gt; clause with &lt;code&gt;GROUP BY&lt;/code&gt;. In this case, the example retrieves all employees whose last name begins with S, and ignores all rows that do not meet this criteria. The G&lt;code&gt;ROUP BY&lt;/code&gt; clause uses the &lt;code&gt;ILIKE&lt;/code&gt; function to retrieve only last names beginning with S. The aggregate function &lt;code&gt;SUM&lt;/code&gt; computes the total vacation days for each group.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT employee_last_name, SUM(vacation_days)
   FROM employee_dimension
   WHERE employee_last_name ILIKE &amp;#39;S%&amp;#39;
   GROUP BY employee_last_name;
 employee_last_name | SUM
--------------------+------
 Sanchez            | 2892
 Smith              | 2672
 Stein              | 2660
(3 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;GROUP BY&lt;/code&gt; clause in the following example groups results by vendor region, and vendor region&#39;s biggest deal:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT vendor_region, MAX(deal_size) AS &amp;#34;Biggest Deal&amp;#34;
   FROM vendor_dimension
   GROUP BY vendor_region;
 vendor_region | Biggest Deal
---------------+--------------
 East          |       990889
 MidWest       |       699163
 NorthWest     |        76101
 South         |       854136
 SouthWest     |       609807
 West          |       964005
(6 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query modifies the previous one with a &lt;code&gt;HAVING&lt;/code&gt; clause, which specifies to return only groups whose maximum deal size exceeds $900,000:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT vendor_region, MAX(deal_size) as &amp;#34;Biggest Deal&amp;#34;
   FROM vendor_dimension
   GROUP BY vendor_region
   HAVING MAX(deal_size) &amp;gt; 900000;
 vendor_region | Biggest Deal
---------------+--------------
 East          |       990889
 West          |       964005
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can use the &lt;code&gt;GROUP BY&lt;/code&gt; clause with one-dimensional arrays of scalar types. In the following example, grants is an ARRAY[VARCHAR] and grant_values is an ARRAY[INT].&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT department, grants, SUM(apply_sum(grant_values))
   FROM employees
   GROUP BY grants, department;
 department |          grants          |  SUM
------------+--------------------------+--------
 Physics    | [&amp;#34;US-7376&amp;#34;,&amp;#34;DARPA-1567&amp;#34;] | 235000
 Astronomy  | [&amp;#34;US-7376&amp;#34;,&amp;#34;DARPA-1567&amp;#34;] |   9000
 Physics    | [&amp;#34;US-7376&amp;#34;]              |  30000
(3 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;GROUP BY&lt;/code&gt; clause without aggregates is similar to using &lt;code&gt;SELECT DISTINCT&lt;/code&gt;. For example, the following two queries return the same results:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT DISTINCT household_id FROM customer_dimension;
=&amp;gt; SELECT household_id FROM customer_dimension GROUP BY household_id;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/cube-aggregate/#&#34;&gt;CUBE aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/group-id/#&#34;&gt;GROUP_ID&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/grouping/#&#34;&gt;GROUPING&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/grouping-id/#&#34;&gt;GROUPING_ID&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/grouping-sets-aggregate/#&#34;&gt;GROUPING SETS aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/rollup-aggregate/&#34;&gt;ROLLUP&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: HAVING clause</title>
      <link>/en/sql-reference/statements/select/having-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/having-clause/</guid>
      <description>
        
        
        &lt;p&gt;Filters the results of a &lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/&#34;&gt;GROUP BY clause&lt;/a&gt;. Semantically, the HAVING clause occurs after the GROUP BY operation. It was added to the SQL standard because a &lt;a href=&#34;../../../../en/sql-reference/statements/select/where-clause/&#34;&gt;WHERE clause&lt;/a&gt; cannot specify &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/&#34;&gt;aggregate functions&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;HAVING &lt;span class=&#34;code-variable&#34;&gt;condition&lt;/span&gt;[,...]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;condition&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Unambiguously references a grouping column, unless the reference appears in an aggregate function.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example returns the employees with salaries greater than $800,000:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT employee_last_name, MAX(annual_salary) as highest_salary FROM employee_dimension
     GROUP BY employee_last_name HAVING MAX(annual_salary) &amp;gt; 800000 ORDER BY highest_salary DESC;
 employee_last_name | highest_salary
--------------------+----------------
 Sanchez            |         992363
 Vogel              |         983634
 Vu                 |         977716
 Lewis              |         957949
 Taylor             |         953373
 King               |         937765
 Gauthier           |         927335
 Garnett            |         903104
 Bauer              |         901181
 Jones              |         885395
 Rodriguez          |         861647
 Young              |         846657
 Greenwood          |         837543
 Overstreet         |         831317
 Garcia             |         811231
(15 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: INTERSECT clause</title>
      <link>/en/sql-reference/statements/select/intersect-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/intersect-clause/</guid>
      <description>
        
        
        &lt;p&gt;Calculates the intersection of the results of two or more SELECT queries. INTERSECT returns distinct values by both the query on the left and right sides of the INTERSECT operand.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;select-stmt
&lt;/span&gt;    INTERSECT &lt;span class=&#34;code-variable&#34;&gt;query&lt;/span&gt;[...]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/#&#34;&gt;order-by-clause&lt;/a&gt;&lt;/span&gt;  [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/offset-clause/#&#34;&gt;offset-clause&lt;/a&gt;&lt;/span&gt; ]]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/limit-clause/#&#34;&gt;limit-clause&lt;/a&gt;&lt;/span&gt; ]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;notes&#34;&gt;Notes&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use the INTERSECT clause to return all elements that are common to the results of all the SELECT queries. The INTERSECT query operates on the results of two or more SELECT queries. INTERSECT returns only the rows that are returned by all the specified queries.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You cannot use the ALL keyword with an INTERSECT query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The results of each SELECT query must be union compatible; they must return the same number of columns, and the corresponding columns must have compatible data types. For example, you cannot use the INTERSECT clause on a column of type INTEGER and a column of type VARCHAR. If the SELECT queries do not meet these criteria, OpenText™ Analytics Database returns an error.&lt;/p&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The &lt;a href=&#34;../../../../en/sql-reference/data-types/data-type-coercion-chart/#&#34;&gt;Data type coercion chart&lt;/a&gt; lists the data types that can be cast to other data types. If one data type can be cast to the other, those two data types are compatible.

&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Order the results of an INTERSECT operation by using an ORDER BY clause. In the ORDER BY list, specify the column names from the leftmost SELECT statement or specify integers that indicate the position of the columns by which to sort.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can use INTERSECT in FROM, WHERE, and HAVING clauses.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The rightmost ORDER BY, LIMIT, or OFFSET clauses in an INTERSECT query do not need to be enclosed in parentheses because the rightmost query specifies that the database perform the operation on the results of the INTERSECT operation. Any ORDER BY, LIMIT, or OFFSET clauses contained in SELECT queries that appear earlier in the INTERSECT query must be enclosed in parentheses.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The order by column names is from the first select.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The database supports INTERSECT noncorrelated subquery predicates. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM T1
   WHERE T1.x IN
      (SELECT MAX(c1) FROM T2
       &lt;span class=&#34;code-input&#34;&gt;INTERSECT &lt;/span&gt;
          SELECT MAX(cc1) FROM T3
       &lt;span class=&#34;code-input&#34;&gt;INTERSECT &lt;/span&gt;
          SELECT MAX(d1) FROM T4);
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Consider the following three tables:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Company_A&lt;/strong&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;id       emp_lname     dept          sales
------+------------+----------------+-------
1234  | Stephen    | auto parts     | 1000
5678  | Alice      | auto parts     | 2500
9012  | Katherine  | floral         |  500
3214  | Smithson   | sporting goods | 1500
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Company_B&lt;/strong&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;id       emp_lname     dept        sales
------+------------+-------------+-------
4321  | Marvin     | home goods  |   250
9012  | Katherine  | home goods  |   500
8765  | Bob        | electronics | 20000
3214  | Smithson   | home goods  |  1500
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Company_C&lt;/strong&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  id  | emp_lname |      dept      | sales
------+-----------+----------------+-------
 3214 | Smithson  | sporting goods |  1500
 5432 | Madison   | sporting goods |   400
 7865 | Cleveland | outdoor        |  1500
 1234 | Stephen   | floral         |  1000
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query returns the IDs and last names of employees that exist in both Company_A and Company_B:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_lname FROM Company_A
   INTERSECT
   SELECT id, emp_lname FROM Company_B;
 id   | emp_lname
------+-----------
 3214 | Smithson
 9012 | Katherine
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query returns the same two employees in descending order of sales:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_lname, sales FROM Company_A
   INTERSECT
   SELECT id, emp_lname, sales FROM Company_B
   ORDER BY sales DESC;
  id  | emp_lname | sales
------+-----------+-------
 3214 | Smithson  |  1500
 9012 | Katherine |   500
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query returns the employee who works for both companies whose sales in Company_B are greater than 1000:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_lname, sales FROM Company_A
   INTERSECT
   (SELECT id, emp_lname, sales FROM company_B WHERE sales &amp;gt; 1000)
   ORDER BY sales DESC;
  id  | emp_lname | sales
------+-----------+-------
 3214 | Smithson  |  1500
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the following query returns the ID and last name of the employee who works for all three companies:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_lname FROM Company_A
    INTERSECT
   SELECT id, emp_lname FROM Company_B
   INTERSECT
   SELECT id, emp_lname FROM Company_C;
  id  | emp_lname
------+-----------
 3214 | Smithson
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query shows the results of a mismatched data types; these two queries are not union compatible:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_lname FROM Company_A
    INTERSECT
   SELECT emp_lname, id FROM Company_B;
ERROR 3429:  For &amp;#39;INTERSECT&amp;#39;, types int and varchar are inconsistent
DETAIL:  Columns: id and emp_lname
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using the &lt;a href=&#34;../../../../en/getting-started/introducing-vmart-example-db/&#34;&gt;VMart&lt;/a&gt; example database, the following query returns information about all Connecticut-based customers who bought items online and whose purchase amounts were between $400 and $500:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_key, customer_name from public.customer_dimension
       WHERE customer_key IN (SELECT customer_key
         FROM online_sales.online_sales_fact
         WHERE sales_dollar_amount &amp;gt; 400
         INTERSECT
         SELECT customer_key FROM online_sales.online_sales_fact
         WHERE sales_dollar_amount &amp;gt; 500)
      AND customer_state = &amp;#39;CT&amp;#39; ORDER BY customer_key;
 customer_key |     customer_name
--------------+------------------------
           39 | Sarah S. Winkler
           44 | Meghan H. Overstreet
           70 | Jack X. Cleveland
          103 | Alexandra I. Vu
          110 | Matt . Farmer
          173 | Mary R. Reyes
          188 | Steve G. Williams
          233 | Theodore V. McNulty
          250 | Marcus E. Williams
          294 | Samantha V. Young
          313 | Meghan P. Pavlov
          375 | Sally N. Vu
          384 | Emily R. Smith
          387 | Emily L. Garcia
...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The previous query and the next one are equivalent, and return the same results:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_key,customer_name FROM public.customer_dimension
       WHERE customer_key IN (SELECT customer_key
      FROM online_sales.online_sales_fact
         WHERE sales_dollar_amount &amp;gt; 400
         AND sales_dollar_amount &amp;lt; 500)
   AND customer_state = &amp;#39;CT&amp;#39; ORDER BY customer_key;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/#&#34;&gt;SELECT&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/except-clause/#&#34;&gt;EXCEPT clause&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/union-clause/#&#34;&gt;UNION clause&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/queries/subqueries/#&#34;&gt;Subqueries&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: INTO TABLE clause</title>
      <link>/en/sql-reference/statements/select/into-table-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/into-table-clause/</guid>
      <description>
        
        
        &lt;p&gt;Creates a table from a query result set.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Permanent table:&lt;/strong&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;INTO [TABLE] [[{&lt;span class=&#34;code-variable&#34;&gt;namespace&lt;/span&gt;. | &lt;span class=&#34;code-variable&#34;&gt;database&lt;/span&gt;. }]&lt;span class=&#34;code-variable&#34;&gt;schema.&lt;/span&gt;]&lt;span class=&#34;code-variable&#34;&gt;table&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Temporary table:&lt;/strong&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;INTO [&lt;span class=&#34;code-variable&#34;&gt;scope&lt;/span&gt;] TEMP[ORARY] [TABLE] [[&lt;span class=&#34;code-variable&#34;&gt;database&lt;/span&gt;.]&lt;span class=&#34;code-variable&#34;&gt;schema.&lt;/span&gt;]&lt;span class=&#34;code-variable&#34;&gt;table&lt;/span&gt;
   [ ON COMMIT { DELETE | PRESERVE } ROWS ]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;scope&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies visibility of a temporary table definition:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;GLOBAL&lt;/code&gt; (default): The table definition is visible to all sessions, and persists until you explicitly drop the table.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;LOCAL&lt;/code&gt;: The table definition is visible only to the session in which it is created, and is dropped when the session ends.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Regardless of this setting, retention of temporary table data is set by the keywords &lt;code&gt;ON COMMIT DELETE ROWS&lt;/code&gt; and &lt;code&gt;ON COMMIT PRESERVE ROWS&lt;/code&gt; (see below).&lt;/p&gt;
&lt;p&gt;For more information, see &lt;a href=&#34;../../../../en/admin/working-with-native-tables/creating-temporary-tables/#&#34;&gt;Creating temporary tables&lt;/a&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;{ &lt;/code&gt;&lt;em&gt;&lt;code&gt;database&lt;/code&gt;&lt;/em&gt; &lt;code&gt;|&lt;/code&gt; &lt;em&gt;&lt;code&gt;namespace&lt;/code&gt;&lt;/em&gt;&lt;code&gt; }&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Name of the database or &lt;a href=&#34;../../../../en/architecture/eon-concepts/shards-and-subscriptions/&#34;&gt;namespace&lt;/a&gt; that contains &lt;em&gt;&lt;code&gt;table&lt;/code&gt;&lt;/em&gt;:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Database name: If specified, it must be the current database.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Namespace name (Eon Mode only): You must specify the namespace of objects in non-default namespaces. If no namespace is provided, it is assumed the object is in the default namespace.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;schema&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Name of the schema, by default &lt;code&gt;public&lt;/code&gt;. If you specify the namespace or database name, you must provide the schema name, even if the schema is &lt;code&gt;public&lt;/code&gt;.
&lt;p&gt;If you specify a schema name that contains a period, the part before the period cannot be the same as the name of an existing namespace.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;

&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;table&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The name of the table to create.&lt;/dd&gt;
&lt;dt&gt;
&lt;code&gt;ON COMMIT  { DELETE | PRESERVE } ROWS&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies whether data is transaction- or session-scoped:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;DELETE&lt;/code&gt; (default) marks the temporary table for transaction-scoped data. OpenText™ Analytics Database removes all table data after each commit.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;PRESERVE&lt;/code&gt; marks the temporary table for session-scoped data, which is preserved beyond the lifetime of a single transaction. The database removes all table data when the session ends.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following &lt;code&gt;SELECT&lt;/code&gt; statement has an &lt;code&gt;INTO TABLE&lt;/code&gt; clause that creates table &lt;code&gt;newTable&lt;/code&gt; from &lt;code&gt;customer_dimension&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * INTO TABLE newTable FROM customer_dimension;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following &lt;code&gt;SELECT&lt;/code&gt; statement creates temporary table &lt;code&gt;newTempTable&lt;/code&gt;. By default, temporary tables are created at a global scope, so its definition is visible to other sessions and persists until it is explicitly dropped. No &lt;code&gt;customer_dimension&lt;/code&gt; data is copied into the new table, and the database issues a warning accordingly:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * INTO TEMP TABLE newTempTable FROM customer_dimension;
WARNING 4102:  No rows are inserted into table &amp;#34;public&amp;#34;.&amp;#34;newTempTable&amp;#34; because
  ON COMMIT DELETE ROWS is the default for create temporary table
HINT:  Use &amp;#34;ON COMMIT PRESERVE ROWS&amp;#34; to preserve the data in temporary table
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following &lt;code&gt;SELECT&lt;/code&gt; statement creates local temporary table &lt;code&gt;newTempTableLocal&lt;/code&gt;. This table is visible only to the session in which it was created, and is automatically dropped when the session ends. The &lt;code&gt;INTO TABLE&lt;/code&gt; clause includes &lt;code&gt;ON COMMIT PRESERVE ROWS&lt;/code&gt;, so the database copies all selection data into the new table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * INTO LOCAL TEMP TABLE newTempTableLocal ON COMMIT PRESERVE ROWS
     FROM customer_dimension;
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: LIMIT clause</title>
      <link>/en/sql-reference/statements/select/limit-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/limit-clause/</guid>
      <description>
        
        
        &lt;p&gt;Specifies the maximum number of result set rows to return, either from the entire result set, or from windows of a partitioned result set.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;   LIMIT { &lt;span class=&#34;code-variable&#34;&gt;num-rows&lt;/span&gt; OVER ( &lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;PARTITION BY&lt;/a&gt; &lt;span class=&#34;code-variable&#34;&gt;partition-expr&lt;/span&gt;[,...] &lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;ORDER BY&lt;/a&gt; &lt;span class=&#34;code-variable&#34;&gt;order-expr&lt;/span&gt;[,...] ) }
           | ALL }
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;num-rows&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The maximum number of rows to return.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies how to partition and sort input data with respect to the current row. The input data is the result set that the query returns after it evaluates FROM, WHERE, GROUP BY, and HAVING clauses.
&lt;p&gt;For details, see &lt;a href=&#34;#Applied&#34;&gt;Using LIMIT with Window Partitioning&lt;/a&gt; below.&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;partition-expr&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Column or expression returning a column to partition results by.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;order-expr&lt;/code&gt;&lt;/em&gt; &lt;code&gt;[ ASC | DESC ] [ NULLS { FIRST | LAST } ]&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Column or expression returning the column to order results by. Each column can be sorted in ascending (default) or descending order, with nulls first or last.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;ALL&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Returns all rows, valid only when LIMIT is applied to the entire result set.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;limiting-returned-rows&#34;&gt;Limiting returned rows&lt;/h2&gt;
&lt;p&gt;LIMIT returns the specified number of rows from the queried dataset. Row precedence is determined by the query&#39;s &lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/&#34;&gt;ORDER BY clause&lt;/a&gt;. If you do not use an ORDER BY clause, the query returns an undefined subset of the result set.&lt;/p&gt;
&lt;p&gt;When a SELECT statement specifies both LIMIT and &lt;a href=&#34;../../../../en/sql-reference/statements/select/offset-clause/&#34;&gt;OFFSET&lt;/a&gt;, OpenText™ Analytics Database first processes the OFFSET, and then applies LIMIT to the remaining rows.&lt;/p&gt;
&lt;p&gt;The following query returns the first 10 rows of data, as ordered first by region and then by number of employees:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sql&#34; data-lang=&#34;sql&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;SELECT&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_region&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_city&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;||&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;, &amp;#39;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;||&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_state&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;location&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;number_of_employees&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;FROM&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_dimension&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;WHERE&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;number_of_employees&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;ORDER&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;BY&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_region&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;number_of_employees&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;LIMIT&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_region&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;location&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_name&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;number_of_employees&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;--------------+----------------+------------+---------------------
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;East&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;         &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Stamford&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;CT&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store219&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;East&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;         &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;New&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Haven&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;CT&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store66&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;East&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;         &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;New&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;York&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NY&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store122&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;MidWest&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;      &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;South&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Bend&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;IN&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store134&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;MidWest&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;      &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Evansville&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;IN&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store30&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;MidWest&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;      &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Green&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Bay&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;WI&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store27&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;South&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Mesquite&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;TX&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store124&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;South&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Cape&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Coral&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;FL&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store18&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;South&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Beaumont&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;TX&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store226&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;South&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Houston&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;TX&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store33&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;rows&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a name=&#34;Applied&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;using-limit-with-window-partitioning&#34;&gt;Using LIMIT with window partitioning&lt;/h2&gt;
&lt;p&gt;You can use LIMIT to apply window partitioning on query results and limit the number of rows that are returned in each window.&lt;/p&gt;
&lt;p&gt;For example, the following query specifies window partitioning on the result set. LIMIT is set to 2, so each window partition can return no more than two rows. The &lt;code&gt;OVER&lt;/code&gt; clause partitions the result set by &lt;code&gt;store_region&lt;/code&gt;, so in each region the query returns the two stores with the smallest number of employees:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sql&#34; data-lang=&#34;sql&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;SELECT&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_region&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_city&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;||&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;, &amp;#39;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;||&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_state&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;location&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;number_of_employees&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;FROM&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_dimension&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;LIMIT&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;OVER&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;PARTITION&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;BY&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_region&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;ORDER&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;BY&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;number_of_employees&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;ASC&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_region&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;      &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;location&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;       &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;store_name&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;number_of_employees&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;--------------+---------------------+------------+---------------------
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;West&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;         &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Norwalk&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;CA&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;         &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store43&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;West&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;         &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Lancaster&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;CA&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;       &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store95&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;East&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;         &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Stamford&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;CT&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store219&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;East&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;         &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;New&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;York&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NY&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store122&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;SouthWest&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;North&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Las&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Vegas&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NV&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store170&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;SouthWest&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Phoenix&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;AZ&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;         &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store228&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NorthWest&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Bellevue&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;WA&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store200&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;19&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NorthWest&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Portland&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;OR&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store39&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;22&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;MidWest&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;      &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;South&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Bend&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;IN&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;      &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store134&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;MidWest&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;      &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Evansville&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;IN&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;      &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store30&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;South&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Mesquite&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;TX&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store124&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;South&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Beaumont&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;TX&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Store226&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                  &lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;rows&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: MATCH clause</title>
      <link>/en/sql-reference/statements/select/match-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/match-clause/</guid>
      <description>
        
        
        &lt;p&gt;A SQL extension that lets you screen large amounts of historical data in search of event patterns, the MATCH clause provides subclasses for analytic partitioning and ordering and matches rows from the result table based on a pattern you define.&lt;/p&gt;
&lt;p&gt;You specify a pattern as a regular expression, which is composed of event types defined in the DEFINE subclause, where each event corresponds to a row in the input table. Then you can search for the pattern within a sequence of input events. Pattern matching returns the contiguous sequence of rows that conforms to PATTERN subclause. For example, pattern &lt;code&gt;P&lt;/code&gt; (&lt;code&gt;A B* C&lt;/code&gt;) consist of three event types: A, B, and C. When OpenText™ Analytics Database finds a match in the input table, the associated pattern instance must be an event of type A followed by 0 or more events of type B, and an event of type C.&lt;/p&gt;
&lt;p&gt;Pattern matching is particularly useful for clickstream analysis where you might want to identify users&#39; actions based on their Web browsing behavior (page clicks). For details, see &lt;a href=&#34;../../../../en/sql-reference/statements/select/match-clause/event-series-pattern-matching/#&#34;&gt;Event series pattern matching&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;MATCH ( [ PARTITION BY &lt;span class=&#34;code-variable&#34;&gt;table-column&lt;/span&gt; ] ORDER BY &lt;span class=&#34;code-variable&#34;&gt;table-column&lt;/span&gt;
    DEFINE &lt;span class=&#34;code-variable&#34;&gt;event-name&lt;/span&gt; AS &lt;span class=&#34;code-variable&#34;&gt;boolean-expr&lt;/span&gt; [,...]
    PATTERN &lt;span class=&#34;code-variable&#34;&gt;pattern-name&lt;/span&gt; AS ( &lt;span class=&#34;code-variable&#34;&gt;regexp&lt;/span&gt;)
    [ &lt;span class=&#34;code-variable&#34;&gt;rows-match-clause&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;PARTITION BY&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Defines the window data scope in which the pattern, defined in the PATTERN subclause, is matched. The partition clause partitions the data by matched patterns defined in the PATTERN subclause. For each partition, data is sorted by the ORDER BY clause. If the partition clause is omitted, the entire data set is considered a single partition.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;ORDER BY&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Defines the window data scope in which the pattern, defined in the PATTERN subclause, is matched. For each partition, the order clause specifies how the input data is ordered for pattern matching.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The ORDER BY clause is mandatory.

&lt;/div&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;DEFINE&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Defines the &lt;a href=&#34;../../../../en/sql-reference/language-elements/predicates/boolean/&#34;&gt;boolean&lt;/a&gt; expressions that make up the event types in the regular expressions. For example:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;DEFINE
 Entry    AS RefURL  NOT ILIKE &amp;#39;%website2.com%&amp;#39; AND PageURL ILIKE
                               &amp;#39;%website2.com%&amp;#39;,
 Onsite   AS PageURL ILIKE     &amp;#39;%website2.com%&amp;#39; AND Action=&amp;#39;V&amp;#39;,
  
 Purchase AS PageURL ILIKE     &amp;#39;%website2.com%&amp;#39; AND Action=&amp;#39;P&amp;#39;
  
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The DEFINE subclause accepts a maximum of 52 events. See &lt;a href=&#34;../../../../en/sql-reference/statements/select/match-clause/event-series-pattern-matching/#&#34;&gt;Event series pattern matching&lt;/a&gt; for examples.&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;event-name&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Name of the event to evaluate for each row—in the earlier example, &lt;code&gt;Entry, Onsite, Purchase&lt;/code&gt;.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Event names are case insensitive and follow the same naming conventions as those used for tables and columns.

&lt;/div&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;boolean-expr&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Expression that returns true or false. boolean_expr can include &lt;a href=&#34;../../../../en/sql-reference/language-elements/operators/logical-operators/#&#34;&gt;Logical operators&lt;/a&gt; and relational &lt;a href=&#34;../../../../en/sql-reference/language-elements/operators/comparison-operators/&#34;&gt;(comparison)&lt;/a&gt; operators. For example:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Purchase AS PageURL ILIKE &amp;#39;%website2.com%&amp;#39; AND Action = &amp;#39;P&amp;#39;
&lt;/code&gt;&lt;/pre&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;PATTERN &lt;/code&gt;&lt;em&gt;&lt;code&gt;pattern-name&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Name of the pattern defined in the PATTERN subclause; for example, P is the pattern name defined below:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt; PATTERN P AS (...)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A PATTERN is a &lt;em&gt;search pattern&lt;/em&gt; that is comprised of a name and a regular expression.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The database supports one pattern per query.

&lt;/div&gt;&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;regexp&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A regular expression comprised of event types defined in the &lt;code&gt;DEFINE&lt;/code&gt; subclause and one or more quantifiers below. When the database evaluates the &lt;code&gt;MATCH&lt;/code&gt; clause, the regular expression identifies the rows that meet the expression criteria.
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;*&lt;/code&gt;: Match 0 or more times&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;*?&lt;/code&gt;: Match 0 or more times, not greedily&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;+&lt;/code&gt;: Match 1 or more times&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;+?&lt;/code&gt;: Match 1 or more times, not greedily&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;?&lt;/code&gt;: Match 0 or 1 time&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;??&lt;/code&gt;: Match 0 or 1 time, not greedily&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;*+&lt;/code&gt;: Match 0 or more times, possessive&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;++&lt;/code&gt;: Match 1 or more times, possessive&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;?+&lt;/code&gt;: Match 0 or 1 time, possessive&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;|&lt;/code&gt;: Alternation. Matches expression before or after the vertical bar. Similar to a Boolean OR.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;rows-match-clause&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies how to resolve more than one event evaluating to true for a single row, one of the following:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ROWS MATCH ALL EVENTS&lt;/code&gt;: If more than one event evaluates to true for a single row, the database returns this error :&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ERROR: pattern events must be mutually exclusive
HINT:  try using ROWS MATCH FIRST EVENT
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ROWS MATCH FIRST EVENT&lt;/code&gt;: If more than one event evaluates to true for a given row, the database uses the first event in the SQL statement for that row.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;/dl&gt;

&lt;h2 id=&#34;pattern-semantic-evaluation&#34;&gt;Pattern semantic evaluation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The semantic evaluating ordering of the SQL clauses is: FROM -&amp;gt; WHERE -&amp;gt; PATTERN MATCH -&amp;gt; SELECT.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Data is partitioned as specified in the PARTITION BY clause. If the partition clause is omitted, the entire data set is considered a single partition.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For each partition, the order clause specifies how the input data is ordered for pattern matching.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Events are evaluated for each row. A row could have 0, 1, or &lt;em&gt;&lt;code&gt;N&lt;/code&gt;&lt;/em&gt; events evaluate to true. If more than one event evaluates to true for the same row, the database returns a run-time error unless you specify ROWS MATCH FIRST EVENT. If you specify ROWS MATCH FIRST EVENT and more than one event evaluates to TRUE for a single row, the database chooses the event that was defined first in the SQL statement to be the event it uses for the row.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The database matches patterns by finding the contiguous sequence of rows that conform to the pattern defined in the PATTERN subclause.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
For each match, the database outputs the rows that contribute to the match. Rows not part of the match (do not satisfy one or more predicates) are not output.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The database reports only non-overlapping matches. If an overlap occurs, the database chooses the first match found in the input stream. After finding the match, the database looks for the next match, starting at the end of the previous match.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The database reports the longest possible match, not a subset of a match. For example, consider pattern: A&lt;em&gt;B with input: AAAB. Because A uses the greedy regular expression quantifier (&lt;/em&gt;), the database reports all A inputs (AAAB), not AAB, AB, or B.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;notes-and-restrictions&#34;&gt;Notes and restrictions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;DISTINCT and GROUP BY/HAVING clauses are not allowed in pattern match queries.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The following expressions are not allowed in the DEFINE subclause:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Subqueries, such as &lt;code&gt;DEFINE X AS c IN ELECT c FROM table&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Analytic functions, such as &lt;code&gt;DEFINE X AS c &amp;lt;&lt;/code&gt; &lt;code&gt;LEA1) OVER (ORDER BY 1)&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Aggregate functions, such as &lt;code&gt;DEFINE X AS c &amp;lt;&lt;/code&gt; &lt;code&gt;MA1)&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You cannot use the same pattern name to define a different event; for example, the following is not allowed for X:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;DEFINE   X AS c1 &amp;lt;  3
  X AS c1  &amp;gt;= 3
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Used with MATCH clause, the database &lt;a href=&#34;../../../../en/sql-reference/functions/match-and-search-functions/match-clause-functions/#&#34;&gt;MATCH clause functions&lt;/a&gt; provide additional data about the patterns it finds. For example, you can use the functions to return values representing the name of the event that matched the input row, the sequential number of the match, or a partition-wide unique identifier for the instance of the pattern that matched.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;For examples, see &lt;a href=&#34;../../../../en/sql-reference/statements/select/match-clause/event-series-pattern-matching/#&#34;&gt;Event series pattern matching&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/match-and-search-functions/match-clause-functions/#&#34;&gt;MATCH clause functions&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/match-and-search-functions/match-clause-functions/event-name/#&#34;&gt;EVENT_NAME&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/match-and-search-functions/match-clause-functions/match-id/#&#34;&gt;MATCH_ID&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/match-and-search-functions/match-clause-functions/pattern-id/#&#34;&gt;PATTERN_ID&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: MINUS clause</title>
      <link>/en/sql-reference/statements/select/minus-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/minus-clause/</guid>
      <description>
        
        
        &lt;p&gt;MINUS is an alias for &lt;a href=&#34;../../../../en/sql-reference/statements/select/except-clause/&#34;&gt;EXCEPT&lt;/a&gt;.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: OFFSET clause</title>
      <link>/en/sql-reference/statements/select/offset-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/offset-clause/</guid>
      <description>
        
        
        &lt;p&gt;Omits a specified number of rows from the beginning of the result set.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;OFFSET &lt;span class=&#34;code-variable&#34;&gt;rows&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;start-row&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies the first row to include in the result set. All preceding rows are omitted.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;dependencies&#34;&gt;Dependencies&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use an &lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/&#34;&gt;ORDER BY clause&lt;/a&gt; with OFFSET. Otherwise, the query returns an undefined subset of the result set.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;OFFSET must follow the &lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/&#34;&gt;ORDER BY clause&lt;/a&gt; in a SELECT statement or UNION clause.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When a SELECT statement or UNION clause specifies both &lt;a href=&#34;../../../../en/sql-reference/statements/select/limit-clause/&#34;&gt;LIMIT&lt;/a&gt; and OFFSET, OpenText™ Analytics Database first processes the OFFSET statement, and then applies the LIMIT statement to the remaining rows.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query returns 14 rows from the &lt;code&gt;customer_dimension&lt;/code&gt; table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_name, customer_gender FROM customer_dimension
   WHERE occupation=&amp;#39;Dancer&amp;#39; AND customer_city = &amp;#39;San Francisco&amp;#39; ORDER BY customer_name;
    customer_name     | customer_gender
----------------------+-----------------
 Amy X. Lang          | Female
 Anna H. Li           | Female
 Brian O. Weaver      | Male
 Craig O. Pavlov      | Male
 Doug Z. Goldberg     | Male
 Harold S. Jones      | Male
 Jack E. Perkins      | Male
 Joseph W. Overstreet | Male
 Kevin . Campbell     | Male
 Raja Y. Wilson       | Male
 Samantha O. Brown    | Female
 Steve H. Gauthier    | Male
 William . Nielson    | Male
 William Z. Roy       | Male
(14 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you modify the previous query to specify an offset of 8 (&lt;code&gt;OFFSET 8&lt;/code&gt;), the database skips the first eight rows of the previous result set. The query returns the following results:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_name, customer_gender FROM customer_dimension
   WHERE occupation=&amp;#39;Dancer&amp;#39; AND customer_city = &amp;#39;San Francisco&amp;#39; ORDER BY customer_name OFFSET 8;
   customer_name   | customer_gender
-------------------+-----------------
 Kevin . Campbell  | Male
 Raja Y. Wilson    | Male
 Samantha O. Brown | Female
 Steve H. Gauthier | Male
 William . Nielson | Male
 William Z. Roy    | Male
(6 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: ORDER BY clause</title>
      <link>/en/sql-reference/statements/select/order-by-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/order-by-clause/</guid>
      <description>
        
        
        &lt;p&gt;Sorts a query result set on one or more columns or column expressions. OpenText™ Analytics Database uses the current locale and collation sequence to compare and sort string values.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The projection data is always stored and sorted by the ASCII (binary) collating sequence.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ORDER BY &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; [ ASC | DESC ] [,...]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression &lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;One of the following:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Name or &lt;a href=&#34;http://en.wikipedia.org/wiki/Ordinal_number&#34;&gt;ordinal number&lt;/a&gt; of a SELECT list item. The ordinal number refers to the position of the result column, counting from the left beginning at one. Use them to order by a column whose name is not unique. Ordinal numbers are invalid for an ORDER BY clause of an analytic function&#39;s &lt;a href=&#34;../../../../en/data-analysis/sql-analytics/invoking-analytic-functions/&#34;&gt;OVER clause&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Arbitrary expression formed from columns that do not appear in the &lt;code&gt;SELECT&lt;/code&gt; list&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/expressions/case-expressions/&#34;&gt;CASE&lt;/a&gt; expression.&lt;br /&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

You cannot use DISTINCT on a collection column if it is also included in the sort order.

&lt;/div&gt;
&lt;/dd&gt;
&lt;dt&gt;ASC | DESC&lt;/dt&gt;
&lt;dd&gt;Specifies whether to sort values in ascending or descending order. NULL values are either first or last in the sort order, depending on data type:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;INTEGER, INT, DATE/TIME: NULL has the smallest value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;FLOAT, BOOLEAN, CHAR, VARCHAR, ARRAY, SET: NULL has the largest value&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The follow example returns all the city and deal size for customer Metamedia, sorted by deal size in descending order.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_city, deal_siz FROM customer_dimension WHERE customer_name = &amp;#39;Metamedia&amp;#39;
   ORDER BY deal_size DESC;
  customer_city   | deal_size
------------------+-----------
 El Monte         |   4479561
 Athens           |   3815416
 Ventura          |   3792937
 Peoria           |   3227765
 Arvada           |   2671849
 Coral Springs    |   2643674
 Fontana          |   2374465
 Rancho Cucamonga |   2214002
 Wichita Falls    |   2117962
 Beaumont         |   1898295
 Arvada           |   1321897
 Waco             |   1026854
 Joliet           |    945404
 Hartford         |    445795
(14 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example uses a transform function. It returns an error because the ORDER BY column is not in the window partition.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE t(geom geometry(200), geog geography(200));
=&amp;gt; SELECT PolygonPoint(geom) OVER(PARTITION BY geom)
   AS SEL_0 FROM t ORDER BY geog;
ERROR 2521: Cannot specify anything other than user defined transforms and partitioning expressions in the ORDER BY list
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example, using the same table, corrects this error.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT PolygonPoint(geom) OVER(PARTITION BY geom)
   AS SEL_0 FROM t ORDER BY geom;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example uses an array in the ORDER BY clause.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM employees
   ORDER BY grant_values;
 id | department |          grants          |  grant_values
----+------------+--------------------------+----------------
 36 | Astronomy  | [&amp;#34;US-7376&amp;#34;,&amp;#34;DARPA-1567&amp;#34;] | [5000,4000]
 36 | Physics    | [&amp;#34;US-7376&amp;#34;,&amp;#34;DARPA-1567&amp;#34;] | [10000,25000]
 33 | Physics    | [&amp;#34;US-7376&amp;#34;]              | [30000]
 42 | Physics    | [&amp;#34;US-7376&amp;#34;,&amp;#34;DARPA-1567&amp;#34;] | [65000,135000]
(4 rows)
&lt;/code&gt;&lt;/pre&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: TIMESERIES clause</title>
      <link>/en/sql-reference/statements/select/timeseries-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/timeseries-clause/</guid>
      <description>
        
        
        &lt;p&gt;Provides gap-filling and interpolation (GFI) computation, an important component of time series analytics computation. See &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/#&#34;&gt;Time series analytics&lt;/a&gt; for details and examples.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;TIMESERIES &lt;span class=&#34;code-variable&#34;&gt;slice-time&lt;/span&gt; AS &amp;#39;&lt;span class=&#34;code-variable&#34;&gt;length-and-time-unit-expr&#39;&lt;/span&gt; OVER (
  [ PARTITION BY &lt;span class=&#34;code-variable&#34;&gt;column-expr&lt;/span&gt;[,...] ] ORDER BY&lt;span class=&#34;code-variable&#34;&gt; time-expr &lt;/span&gt;) [ ORDER BY &lt;span class=&#34;code-variable&#34;&gt;table-column&lt;/span&gt;[,...] ]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;slice-time&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A time column produced by the &lt;code&gt;TIMESERIES&lt;/code&gt; clause, which stores the time slice start times generated from gap filling.
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This parameter is an alias, so you can use any name that an alias would take.&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;length-and-time-unit-expr&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;An &lt;code&gt;INTERVAL DAY TO SECOND&lt;/code&gt; literal that specifies the length of time unit of time slice computation. For example:
&lt;p&gt;`TIMESERIES slice_time AS &#39;3 seconds&#39; ...&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies partitioning and ordering for the function. &lt;code&gt;OVER()&lt;/code&gt; also specifies that the time series function operates on a query result set—that is, the rows that are returned after the &lt;code&gt;FROM&lt;/code&gt;, &lt;code&gt;WHERE&lt;/code&gt;, &lt;code&gt;GROUP BY&lt;/code&gt;, and &lt;code&gt;HAVING&lt;/code&gt; clauses are evaluated.&lt;/dd&gt;
&lt;dt&gt;
&lt;code&gt;PARTITION BY (&lt;span class=&#34;code-variable&#34;&gt;column-expr&lt;/span&gt;`[,...] )`&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Partitions the data by the specified column expressions. &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/&#34;&gt;Gap filling and interpolation&lt;/a&gt; is performed on each partition separately.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;ORDER BY &lt;/code&gt;&lt;em&gt;&lt;code&gt;time-expr&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Sorts the data by the &lt;code&gt;TIMESTAMP&lt;/code&gt; expression &lt;em&gt;&lt;code&gt;time-expr&lt;/code&gt;&lt;/em&gt;, which computes the time information of the time series data. 
&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The &lt;code&gt;TIMESERIES&lt;/code&gt; clause requires an &lt;code&gt;ORDER BY&lt;/code&gt; operation on the timestamp column.

&lt;/div&gt;&lt;/dd&gt;
&lt;/dl&gt;

&lt;h2 id=&#34;notes&#34;&gt;Notes&lt;/h2&gt;
&lt;p&gt;If the &lt;em&gt;&lt;code&gt;window-partition-clause&lt;/code&gt;&lt;/em&gt; is not specified in TIMESERIES OVER(), for each defined time slice, exactly one output record is produced; otherwise, one output record is produced per partition per time slice. Interpolation is computed there.&lt;/p&gt;
&lt;p&gt;Given a query block that contains a TIMESERIES clause, the following are the semantic phases of execution (after evaluating the FROM and the optional WHERE clauses):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Compute &lt;em&gt;&lt;code&gt;time-expression.&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Perform the same computation as the TIME_SLICE() function on each input record based on the result of &lt;em&gt;&lt;code&gt;time-exp&lt;/code&gt;&lt;/em&gt; and &#39;&lt;em&gt;&lt;code&gt;length-and-time-unit-expr&#39;&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Perform gap filling to generate time slices missing from the input.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Name the result of this computation as &lt;em&gt;&lt;code&gt;slice_time&lt;/code&gt;&lt;/em&gt;, which represents the generated &amp;quot;time series&amp;quot; column (alias) after gap filling.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Partition the data by &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;, &lt;em&gt;&lt;code&gt;slice-time&lt;/code&gt;&lt;/em&gt;. For each partition, do step 4.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Sort the data by &lt;em&gt;&lt;code&gt;time-expr&lt;/code&gt;&lt;/em&gt;. Interpolation is computed here.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;There is semantic overlap between the TIMESERIES clause and the &lt;a href=&#34;../../../../en/sql-reference/functions/data-type-specific-functions/datetime-functions/time-slice/#&#34;&gt;TIME_SLICE&lt;/a&gt; function with the following key differences:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;TIMESERIES&lt;/code&gt; only supports the &lt;a href=&#34;../../../../en/sql-reference/language-elements/literals/datetime-literals/interval-literal/interval-qualifier/&#34;&gt;interval qualifier&lt;/a&gt; &lt;code&gt;DAY TO SECOND&lt;/code&gt;; it does not allow &lt;code&gt;YEAR TO MONTH&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Unlike &lt;code&gt;TIME_SLICE&lt;/code&gt;, the time slice length and time unit expressed in *&lt;code&gt;length-and-time-unit-expr &lt;/code&gt;*must be constants so gaps in the time slices are well-defined.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;TIMESERIES&lt;/code&gt; performs gap filling; the &lt;code&gt;TIME_SLICE&lt;/code&gt; function does not.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;TIME_SLICE&lt;/code&gt; can return the start or end time of a time slice, depending on the value of its fourth input parameter (&lt;em&gt;&lt;code&gt;start-or-end&lt;/code&gt;&lt;/em&gt;). &lt;code&gt;TIMESERIES&lt;/code&gt;, on the other hand, always returns the start time of each time slice. To output the end time of each time slice, write a &lt;code&gt;SELECT&lt;/code&gt; statement like the following:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time + &amp;lt;slice_length&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;restrictions&#34;&gt;Restrictions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;When the &lt;code&gt;TIMESERIES&lt;/code&gt; clause occurs in a SQL query block, only the following clauses can be used in the same query block:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;SELECT&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;FROM&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;WHERE&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ORDER BY&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;GROUP BY&lt;/code&gt; and &lt;code&gt;HAVING&lt;/code&gt; clauses are not allowed. If a &lt;code&gt;GROUP BY&lt;/code&gt; operation is needed before or after gap-filling and interpolation (GFI), use a subquery and place the &lt;code&gt;GROUP BY&lt;/code&gt; In the outer query. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT symbol, AVG(first_bid) as avg_bid FROM (
        SELECT symbol, slice_time, TS_FIRST_VALUE(bid1) AS first_bid
        FROM Tickstore
        WHERE symbol IN (&amp;#39;MSFT&amp;#39;, &amp;#39;IBM&amp;#39;)
        TIMESERIES slice_time AS &amp;#39;5 seconds&amp;#39; OVER (PARTITION BY symbol ORDER BY ts)
        ) AS resultOfGFI
GROUP BY symbol;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When the &lt;code&gt;TIMESERIES&lt;/code&gt; clause is present in the SQL query block, the &lt;code&gt;SELECT&lt;/code&gt; list can include only the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Time series aggregate functions such as 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/ts-first-value/#&#34;&gt;TS_FIRST_VALUE&lt;/a&gt;&lt;/code&gt; and 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/ts-last-value/#&#34;&gt;TS_LAST_VALUE&lt;/a&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;code&gt;slice_time&lt;/code&gt;&lt;/em&gt; column&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;PARTITION BY&lt;/code&gt; expressions&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/data-type-specific-functions/datetime-functions/time-slice/#&#34;&gt;TIME_SLICE&lt;/a&gt;&lt;/code&gt; function&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, the following two queries return a syntax error because &lt;code&gt;bid1&lt;/code&gt; is not a &lt;code&gt;PARTITION BY&lt;/code&gt; or &lt;code&gt;GROUP BY&lt;/code&gt; column:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT bid, symbol, TS_FIRST_VALUE(bid) FROM Tickstore
   TIMESERIES slice_time AS &amp;#39;5 seconds&amp;#39; OVER (PARTITION BY symbol ORDER BY ts);
   ERROR:  column &amp;#34;Tickstore.bid&amp;#34; must appear in the PARTITION BY list of Timeseries clause or be used in a Timeseries Output function
=&amp;gt; SELECT bid, symbol, AVG(bid) FROM Tickstore
   GROUP BY symbol;
   ERROR:  column &amp;#34;Tickstore.bid&amp;#34; must appear in the GROUP BY clause or be used in an aggregate function
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;For examples, see &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/#&#34;&gt;Gap filling and interpolation (GFI)&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/data-type-specific-functions/datetime-functions/time-slice/#&#34;&gt;TIME_SLICE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/ts-first-value/#&#34;&gt;TS_FIRST_VALUE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/ts-last-value/#&#34;&gt;TS_LAST_VALUE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/#&#34;&gt;Gap filling and interpolation (GFI)&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: UNION clause</title>
      <link>/en/sql-reference/statements/select/union-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/union-clause/</guid>
      <description>
        
        
        &lt;p&gt;Combines the results of multiple SELECT statements. You can include UNION in &lt;a href=&#34;../../../../en/sql-reference/statements/select/from-clause/&#34;&gt;FROM&lt;/a&gt;, &lt;a href=&#34;../../../../en/sql-reference/statements/select/where-clause/&#34;&gt;WHERE&lt;/a&gt;, and &lt;a href=&#34;../../../../en/sql-reference/statements/select/having-clause/&#34;&gt;HAVING&lt;/a&gt; clauses.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;select&lt;/span&gt; { UNION [ ALL | DISTINCT ] &lt;span class=&#34;code-variable&#34;&gt;select&lt;/span&gt; }[...]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/#&#34;&gt;order-by-clause&lt;/a&gt;&lt;/span&gt;  [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/offset-clause/#&#34;&gt;offset-clause&lt;/a&gt;&lt;/span&gt; ]]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/limit-clause/#&#34;&gt;limit-clause&lt;/a&gt;&lt;/span&gt; ]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;select&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A &lt;a href=&#34;../../../../en/sql-reference/statements/select/#&#34;&gt;SELECT&lt;/a&gt; statement that returns one or more rows, depending on whether you specify keywords DISTINCT or ALL.
&lt;p&gt;The first SELECT statement can include the &lt;a href=&#34;../../../../en/sql-reference/language-elements/hints/label/#&#34;&gt;LABEL&lt;/a&gt; hint. OpenText™ Analytics Database ignores LABEL hints in subsequent SELECT statements.&lt;/p&gt;
&lt;p&gt;Each SELECT statement can specify its own &lt;a href=&#34;#UnionClauses&#34;&gt;ORDER BY&lt;/a&gt;, &lt;a href=&#34;../../../../en/sql-reference/statements/select/limit-clause/&#34;&gt;LIMIT&lt;/a&gt;, and &lt;a href=&#34;../../../../en/sql-reference/statements/select/offset-clause/&#34;&gt;OFFSET&lt;/a&gt; clauses. A SELECT statement with one or more of these clauses must be enclosed by parentheses. See also: &lt;a href=&#34;#UnionClauses&#34;&gt;ORDER BY, LIMIT, and OFFSET Clauses in UNION&lt;/a&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;DISTINCT&lt;/code&gt;, &lt;code&gt;ALL&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;How to return duplicate rows:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;DISTINCT (default) returns only unique rows.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;ALL concatenates all rows, including duplicates. For best performance, use UNION ALL.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;UNION ALL supports columns of complex types; UNION DISTINCT does not.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;requirements&#34;&gt;Requirements&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Each row of the UNION result set must be in the result set of at least one of its SELECT statements.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Each SELECT statement must specify the same number of columns.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Data types of corresponding SELECT statement columns must be &lt;a href=&#34;../../../../en/sql-reference/data-types/data-type-coercion-chart/&#34;&gt;compatible&lt;/a&gt;, otherwise the database returns an error.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;order-by-limit-and-offset-clauses-in-union&#34;&gt;ORDER BY, LIMIT, and OFFSET clauses in UNION&lt;/h2&gt;
&lt;p&gt;&lt;a name=&#34;UnionClauses&#34;&gt;&lt;/a&gt;
A UNION statement can specify its own &lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/&#34;&gt;ORDER BY&lt;/a&gt;, &lt;a href=&#34;../../../../en/sql-reference/statements/select/limit-clause/&#34;&gt;LIMIT&lt;/a&gt;, and &lt;a href=&#34;../../../../en/sql-reference/statements/select/offset-clause/&#34;&gt;OFFSET&lt;/a&gt; clauses, as in the following example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_name FROM company_a UNION ALL SELECT id, emp_name FROM company_b ORDER BY emp_name LIMIT 2;
  id  | emp_name
------+----------
 5678 | Alice
 8765 | Bob
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each SELECT statement in a UNION clause can specify its own ORDER BY, LIMIT, and OFFSET clauses. The database processes the SELECT statement clauses before it processes the UNION clauses. In the following example, the database processes the individual queries and then concatenates the two result sets:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; (SELECT id, emp_name FROM company_a ORDER BY emp_name LIMIT 2)
   UNION ALL
   (SELECT id, emp_name FROM company_b ORDER BY emp_name LIMIT 2);
  id  | emp_name
------+-----------
 5678 | Alice
 9012 | Katherine
 8765 | Bob
 9012 | Katherine
(4 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following requirements and restrictions determine how the database processes a UNION clause that contains &lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/&#34;&gt;ORDER BY&lt;/a&gt;, &lt;a href=&#34;../../../../en/sql-reference/statements/select/limit-clause/&#34;&gt;LIMIT&lt;/a&gt;, and &lt;a href=&#34;../../../../en/sql-reference/statements/select/offset-clause/&#34;&gt;OFFSET&lt;/a&gt; clauses:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A UNION&#39;s ORDER BY clause must specify columns from the first (leftmost) SELECT statement.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;ORDER BY must precede LIMIT and OFFSET.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When a SELECT or UNION statement specifies both LIMIT and OFFSET, the database first processes the OFFSET statement, and then applies the LIMIT statement to the remaining rows.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;union-in-non-correlated-subqueries&#34;&gt;UNION in non-correlated subqueries&lt;/h2&gt;
&lt;p&gt;The database supports UNION in &lt;a href=&#34;../../../../en/data-analysis/queries/subqueries/noncorrelated-and-correlated-subqueries/&#34;&gt;noncorrelated subquery predicates&lt;/a&gt;. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT DISTINCT customer_key, customer_name FROM public.customer_dimension
   WHERE customer_key IN
     (SELECT customer_key FROM store.store_sales_fact WHERE sales_dollar_amount &amp;gt; 500
      UNION ALL
      SELECT customer_key FROM online_sales.online_sales_fact WHERE sales_dollar_amount &amp;gt; 500)
   AND customer_state = &amp;#39;CT&amp;#39;;
 customer_key |     customer_name
--------------+------------------------
         7021 | Luigi T. Dobisz
         1971 | Betty V. Dobisz
        46284 | Ben C. Gauthier
        33885 | Tanya Y. Taylor
         5449 | Sarah O. Robinson
        29059 | Sally Z. Fortin
        11200 | Foodhope
        15582 | John J. McNulty
        24638 | Alexandra F. Jones
 ...
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;union-all-with-complex-types&#34;&gt;UNION ALL with complex types&lt;/h2&gt;
&lt;p&gt;You can use UNION ALL with complex types. Consider a table with the following definition:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE restaurants(
    name VARCHAR, cuisine VARCHAR,
    locations ARRAY[ROW(city VARCHAR(50), state VARCHAR(2)),50],
    menu ARRAY[ROW(item VARCHAR(50), price FLOAT),100] );
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Suppose you are in a new city looking for a place to eat. The database has information about the following restaurants:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT name, cuisine FROM restaurants
   WHERE CONTAINS(locations,ROW(&amp;#39;Pittsburgh&amp;#39;, &amp;#39;PA&amp;#39;));
       name        | cuisine
-------------------+----------
 Bakersfield Tacos | Mexican
 Bob&amp;#39;s pizzeria    | Italian
 Succulent Steaks  | American
 Sushi House       | Asian
 Villa Milano      | Italian
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Suppose you are hungry for Italian food. If you cannot have Italian, you want something inexpensive. The following query uses two SELECT clauses from the same table, one finding menu items for Italian restaurants and one finding menu items under $10:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; WITH menu_entries AS
    (SELECT name, cuisine,
            EXPLODE(menu USING PARAMETERS skip_partitioning=true) AS (idx, menu_entry)
     FROM restaurants WHERE CONTAINS(locations,ROW(&amp;#39;Pittsburgh&amp;#39;, &amp;#39;PA&amp;#39;)))
   SELECT name, cuisine, menu_entry FROM menu_entries WHERE cuisine = &amp;#39;Italian&amp;#39;
   UNION ALL
   SELECT name, cuisine, menu_entry FROM menu_entries WHERE menu_entry.price &amp;lt;= 10;
       name        | cuisine |                 menu_entry
-------------------+---------+--------------------------------------------
 Bob&amp;#39;s pizzeria    | Italian | {&amp;#34;item&amp;#34;:&amp;#34;cheese pizza&amp;#34;,&amp;#34;price&amp;#34;:8.25}
 Bob&amp;#39;s pizzeria    | Italian | {&amp;#34;item&amp;#34;:&amp;#34;spinach pizza&amp;#34;,&amp;#34;price&amp;#34;:10.5}
 Villa Milano      | Italian | {&amp;#34;item&amp;#34;:&amp;#34;pasta carbonara&amp;#34;,&amp;#34;price&amp;#34;:24.99}
 Villa Milano      | Italian | {&amp;#34;item&amp;#34;:&amp;#34;eggplant parmesan&amp;#34;,&amp;#34;price&amp;#34;:23.49}
 Villa Milano      | Italian | {&amp;#34;item&amp;#34;:&amp;#34;herbed salmon&amp;#34;,&amp;#34;price&amp;#34;:28.99}
 Bakersfield Tacos | Mexican | {&amp;#34;item&amp;#34;:&amp;#34;veggie taco&amp;#34;,&amp;#34;price&amp;#34;:9.95}
 Bob&amp;#39;s pizzeria    | Italian | {&amp;#34;item&amp;#34;:&amp;#34;cheese pizza&amp;#34;,&amp;#34;price&amp;#34;:8.25}
(7 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You cannot use LIMIT OVER with UNION ALL if the selected columns are of complex types. In this case, the statement returns an error like &amp;quot;Multi-value expressions are not supported in this context&amp;quot;. You can still use LIMIT OVER in a single SELECT statement by using parentheses to make the scoping explicit.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;Examples&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The examples that follow use these two tables:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM company_a;
  ID    emp_name       dept       sales
------+------------+-------------+-------
1234  | Stephen    | auto parts  | 1000
5678  | Alice      | auto parts  | 2500
9012  | Katherine  | floral      |  500

=&amp;gt; SELECT * FROM company_b;
  ID    emp_name       dept       sales
------+------------+-------------+-------
4321  | Marvin     | home goods  |   250
9012  | Katherine  | home goods  |   500
8765  | Bob        | electronics | 20000
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query finds all employee IDs and names from the two tables. The UNION statement uses DISTINCT to combine unique IDs and last names of employees. Katherine works for both companies, so she appears only once in the result set. DISTINCT is the default and can be omitted:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_name FROM company_a
   UNION DISTINCT SELECT id, emp_name FROM company_b ORDER BY id;
  id  | emp_name
------+-----------
 1234 | Stephen
 4321 | Marvin
 5678 | Alice
 8765 | Bob
 9012 | Katherine
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If the UNION statement instead uses ALL, the query returns two records for Katherine:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_name FROM company_a
   UNION ALL SELECT id, emp_name FROM company_b ORDER BY id;
  id  | emp_name
------+-----------
 1234 | Stephen
 5678 | Alice
 9012 | Katherine
 4321 | Marvin
 9012 | Katherine
 8765 | Bob
(6 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query returns the top two salespeople in each company. Each SELECT statement specifies its own ORDER BY and LIMIT clauses, and the UNION statement concatenates the result sets as returned by each query:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; (SELECT id, emp_name, sales FROM company_a ORDER BY sales DESC LIMIT 2)
   UNION ALL
   (SELECT id, emp_name, sales FROM company_b ORDER BY sales DESC LIMIT 2);
  id  |  emp_name | sales
------+-----------+-------
 8765 | Bob       | 20000
 5678 | Alice     |  2500
 1234 | Stephen   |  1000
 9012 | Katherine |   500
(4 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query returns all employees in both companies with an overall ordering. The ORDER BY clause is part of the UNION statement:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT id, emp_name, sales FROM company_a
   UNION
   SELECT id, emp_name, sales FROM company_b
   ORDER BY sales;
  id  |  emp_name | sales
------+-----------+-------
 4321 | Marvin    |   250
 9012 | Katherine |   500
 1234 | Stephen   |  1000
 5678 | Alice     |  2500
 8765 | Bob       | 20000
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query groups total sales by department within each company. Each SELECT statement has its own GROUP BY clause. UNION combines the aggregate results from each query:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; (SELECT &amp;#39;Company A&amp;#39; as company, dept, SUM(sales) FROM company_a
    GROUP BY dept)
    UNION
   (SELECT &amp;#39;Company B&amp;#39; as company, dept, SUM(sales) FROM company_b
    GROUP BY dept)
    ORDER BY 1;
 company   |    dept     |  sum
-----------+-------------+-------
 Company A | auto parts  |  3500
 Company A | floral      |   500
 Company B | electronics | 20000
 Company B | home goods  |   750
(4 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/#&#34;&gt;SELECT&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/except-clause/#&#34;&gt;EXCEPT clause&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/intersect-clause/#&#34;&gt;INTERSECT clause&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/queries/subqueries/#&#34;&gt;Subqueries&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: WHERE clause</title>
      <link>/en/sql-reference/statements/select/where-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/where-clause/</guid>
      <description>
        
        
        &lt;p&gt;Specifies which rows to include in a query&#39;s result set.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;WHERE &lt;span class=&#34;code-variable&#34;&gt;boolean-expression&lt;/span&gt; [ &lt;span class=&#34;code-variable&#34;&gt;subquery&lt;/span&gt; ]...
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;boolean-expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;An expression that returns true or false. The result set only includes rows that evaluate to true. The expression can include &lt;a href=&#34;../../../../en/sql-reference/language-elements/operators/logical-operators/&#34;&gt;boolean operators&lt;/a&gt; and the following predicate elements:
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/language-elements/predicates/between/#&#34;&gt;BETWEEN&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/language-elements/predicates/boolean/#&#34;&gt;Boolean&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/language-elements/predicates/in/#&#34;&gt;IN&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/language-elements/predicates/like/#&#34;&gt;LIKE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/language-elements/predicates/null/#&#34;&gt;NULL&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Use parentheses to group expressions, predicates, and boolean operators. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;... WHERE NOT (A=1 AND B=2) OR C=3;
&lt;/code&gt;&lt;/pre&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example returns the names of all customers in the Eastern region whose name starts with the string &lt;code&gt;Amer&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT DISTINCT customer_name
   FROM customer_dimension
   WHERE customer_region = &amp;#39;East&amp;#39;
   AND customer_name ILIKE &amp;#39;Amer%&amp;#39;;
 customer_name
---------------
 Americare
 Americom
 Americore
 Americorp
 Ameridata
 Amerigen
 Amerihope
 Amerimedia
 Amerishop
 Ameristar
 Ameritech
(11 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: WITH clause</title>
      <link>/en/sql-reference/statements/select/with-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/with-clause/</guid>
      <description>
        
        
        &lt;p&gt;A WITH clause defines one or more named &lt;a href=&#34;https://www.essentialsql.com/introduction-common-table-expressions-ctes/&#34;&gt;common table expressions&lt;/a&gt; (CTEs), where each CTE encapsulates a result set that can be referenced by another CTE in the same WITH clause, or by the primary query. OpenText™ Analytics Database can evaluate WITH clauses in two ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/with-clause/inline-expansion-of-with-clause/&#34;&gt;Inline expansion&lt;/a&gt; (default): The database evaluates each WITH clause every time it is referenced by the primary query.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/with-clause/materialization-of-with-clause/&#34;&gt;Materialization&lt;/a&gt;: The database evaluates each WITH clause once, stores results in a temporary table, and references this table as often as the query requires.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In both cases, WITH clauses can help simplify complicated queries and avoid statement repetition.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;WITH [ /*+ENABLE_WITH_CLAUSE_MATERIALIZATION */ ] [ RECURSIVE ] {
   &lt;span class=&#34;code-variable&#34;&gt;cte-identifier&lt;/span&gt; [ ( &lt;span class=&#34;code-variable&#34;&gt;column-aliases&lt;/span&gt; ) ] AS (
   [ &lt;span class=&#34;code-variable&#34;&gt;subordinate-WITH-clause&lt;/span&gt; ]
   &lt;span class=&#34;code-variable&#34;&gt;query-expression&lt;/span&gt; )
} [,...]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;/*+ENABLE_WITH_CLAUSE_MATERIALIZATION*/&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Enables materialization of all queries in the current WITH clause. Otherwise, materialization is set by configuration parameter WithClauseMaterialization, by default set to 0 (disabled). If WithClauseMaterialization is disabled, materialization is automatically cleared when the primary query of the WITH clause returns. For details, see &lt;a href=&#34;../../../../en/sql-reference/statements/select/with-clause/materialization-of-with-clause/#&#34;&gt;Materialization of WITH clause&lt;/a&gt;.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;RECURSIVE&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies to iterate over the WITH clause&#39;s own result set, through repeated execution of an embedded UNION or UNION ALL statement. For details, see &lt;a href=&#34;../../../../en/sql-reference/statements/select/with-clause/with-clause-recursion/#&#34;&gt;WITH clause recursion&lt;/a&gt;.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;cte-identifier&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Identifies a common table expression (CTE) within a WITH clause. This identifier is available to CTEs of the same WITH clause, and of parent and child WITH clauses (if any). CTE identifiers of the outermost (primary) WITH clause are also available to the primary query.
&lt;p&gt;All CTE identifiers of the same WITH clause must be unique. For example, the following WITH clause defines two CTEs, so they require unique identifiers: &lt;code&gt;regional_sales&lt;/code&gt; and &lt;code&gt;top_regions&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  
WITH
-- query sale amounts for each region
   regional_sales AS (SELECT ... ),
   top_regions AS ( SELECT ... )
   )
&lt;/code&gt;&lt;/pre&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;column-aliases&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A comma-delimited list of result set column aliases. The list of aliases must map to all column expressions in the CTE query. If omitted, result set columns can only be referenced by the names used in the query.
&lt;p&gt;In the following example, the &lt;code&gt;revenue&lt;/code&gt; CTE specifies two column aliases: &lt;code&gt;vkey&lt;/code&gt; and &lt;code&gt;total_revenue&lt;/code&gt;. These map to column &lt;code&gt;vendor_key&lt;/code&gt; and aggregate expression &lt;code&gt;SUM(total_order_cost)&lt;/code&gt;, respectively. The primary query references these aliases:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  
WITH revenue ( vkey, &lt;span class=&#34;code-input&#34;&gt;total_revenue&lt;/span&gt; ) AS (
   SELECT &lt;span class=&#34;code-input&#34;&gt;vendor_key&lt;/span&gt;, SUM(&lt;span class=&#34;code-input&#34;&gt;total_order_cost&lt;/span&gt;)
   FROM store.store_orders_fact
   GROUP BY vendor_key ORDER BY vendor_key)
  
SELECT v.vendor_name, v.vendor_address, v.vendor_city, r.&lt;span class=&#34;code-input&#34;&gt;total_revenue&lt;/span&gt;
FROM vendor_dimension v JOIN revenue r ON v.vendor_key = r.vkey
WHERE r.&lt;span class=&#34;code-input&#34;&gt;total_revenue&lt;/span&gt; = (SELECT MAX(&lt;span class=&#34;code-input&#34;&gt;total_revenue&lt;/span&gt;) FROM revenue )
ORDER BY vendor_name;
&lt;/code&gt;&lt;/pre&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;subordinate-WITH-clause&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A WITH clause that is nested within the current one. CTEs of this WITH clause can only reference CTEs of the same clause, and of parent and child WITH clauses.

&lt;div class=&#34;admonition important&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Important&lt;/h4&gt;
The primary query can only reference CTEs in the outermost WITH clause. It cannot reference the CTEs of any nested WITH clause.
&lt;/div&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;query-expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The query of a given CTE.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;restrictions&#34;&gt;Restrictions&lt;/h2&gt;
&lt;p&gt;WITH clauses only support SELECT and INSERT statements. They do not support UPDATE or DELETE statements.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

For examples that show usage of recursive WITH clauses, see &lt;a href=&#34;../../../../en/sql-reference/statements/select/with-clause/with-clause-recursion/#&#34;&gt;WITH clause recursion&lt;/a&gt;.

&lt;/div&gt;
&lt;h3 id=&#34;single-with-clause-with-single-cte&#34;&gt;Single WITH clause with single CTE&lt;/h3&gt;
&lt;p&gt;The following SQL defines a WITH clause with one CTE, &lt;code&gt;revenue&lt;/code&gt;, which aggregates data in table &lt;code&gt;store.store_orders_fact&lt;/code&gt;. The primary query references the WITH clause result set twice: in its &lt;code&gt;JOIN&lt;/code&gt; clause and predicate:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;-- define WITH clause
WITH revenue ( vkey, total_revenue ) AS (
      SELECT vendor_key, SUM(total_order_cost)
      FROM store.store_orders_fact
      GROUP BY vendor_key ORDER BY 1)
-- End WITH clause

-- primary query
SELECT v.vendor_name, v.vendor_address, v.vendor_city, r.total_revenue
FROM vendor_dimension v JOIN revenue r ON v.vendor_key = r.vkey
WHERE r.total_revenue = (SELECT MAX(total_revenue) FROM revenue )
ORDER BY vendor_name;
   vendor_name    | vendor_address | vendor_city | total_revenue
------------------+----------------+-------------+---------------
 Frozen Suppliers | 471 Mission St | Peoria      |      49877044
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;single-with-clause-and-multiple-ctes&#34;&gt;Single WITH clause and multiple CTEs&lt;/h3&gt;
&lt;p&gt;In the following example, the WITH clause contains two CTEs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;regional_sales&lt;/code&gt; totals sales for each region&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;top_regions&lt;/code&gt; uses the result set from &lt;code&gt;regional_sales&lt;/code&gt; to identify the three regions with the highest sales:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The primary query aggregates sales by region and departments in the &lt;code&gt;top_regions&lt;/code&gt; result set:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
WITH
-- query sale amounts for each region
   regional_sales (region, total_sales) AS (
        SELECT sd.store_region, SUM(of.total_order_cost) AS total_sales
        FROM store.store_dimension sd JOIN store.store_orders_fact of ON sd.store_key = of.store_key
        GROUP BY store_region ),
-- query previous result set
   top_regions AS (
        SELECT region, total_sales
        FROM regional_sales ORDER BY total_sales DESC LIMIT 3
     )

-- primary query
-- aggregate sales in top_regions result set
SELECT sd.store_region AS region, pd.department_description AS department, SUM(of.total_order_cost) AS product_sales
FROM store.store_orders_fact of
JOIN store.store_dimension sd ON sd.store_key = of.store_key
JOIN public.product_dimension pd ON of.product_key = pd.product_key
WHERE sd.store_region IN (SELECT region FROM top_regions)
GROUP BY ROLLUP (region, department) ORDER BY region, product_sales DESC, GROUPING_ID();

 region  |            department            | product_sales
---------+----------------------------------+---------------
 East    |                                  |    1716917786
 East    | Meat                             |     189837962
 East    | Produce                          |     170607880
 East    | Photography                      |     162271618
 East    | Frozen Goods                     |     141077867
 East    | Gifts                            |     137604397
 East    | Bakery                           |     136497842
 East    | Liquor                           |     130410463
 East    | Canned Goods                     |     128683257
 East    | Cleaning supplies                |     118996326
 East    | Dairy                            |     118866901
 East    | Seafood                          |     109986665
 East    | Medical                          |     100404891
 East    | Pharmacy                         |      71671717
 MidWest |                                  |    1287550770
 MidWest | Meat                             |     141446607
 MidWest | Produce                          |     125156100
 MidWest | Photography                      |     122666753
 MidWest | Frozen Goods                     |     105893534
 MidWest | Gifts                            |     103088595
 MidWest | Bakery                           |     102844467
 MidWest | Canned Goods                     |      97647270
 MidWest | Liquor                           |      97306898
 MidWest | Cleaning supplies                |      90775242
 MidWest | Dairy                            |      89065443
 MidWest | Seafood                          |      82541528
 MidWest | Medical                          |      76674814
 MidWest | Pharmacy                         |      52443519
 West    |                                  |    2159765937
 West    | Meat                             |     235841506
 West    | Produce                          |     215277204
 West    | Photography                      |     205949467
 West    | Frozen Goods                     |     178311593
 West    | Bakery                           |     172824555
 West    | Gifts                            |     172134780
 West    | Liquor                           |     164798022
 West    | Canned Goods                     |     163330813
 West    | Cleaning supplies                |     148776443
 West    | Dairy                            |     145244575
 West    | Seafood                          |     139464407
 West    | Medical                          |     126184049
 West    | Pharmacy                         |      91628523
         |                                  |    5164234493
(43 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;insert-statement-that-includes-with-clause&#34;&gt;INSERT statement that includes WITH clause&lt;/h3&gt;
&lt;p&gt;The following SQL uses a WITH clause to insert data from a JOIN query into table &lt;code&gt;total_store_sales&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CREATE TABLE total_store_sales (store_key int, region VARCHAR(20), store_sales numeric (12,2));

INSERT INTO total_store_sales
WITH store_sales AS (
        SELECT sd.store_key, sd.store_region::VARCHAR(20), SUM (of.total_order_cost)
        FROM store.store_dimension sd JOIN store.store_orders_fact of ON sd.store_key = of.store_key
        GROUP BY sd.store_region, sd.store_key ORDER BY sd.store_region, sd.store_key)
SELECT * FROM store_sales;

=&amp;gt; SELECT * FROM total_store_sales ORDER BY region, store_key;
 store_key |  region   | store_sales
-----------+-----------+-------------
         2 | East      | 47668303.00
         6 | East      | 48136354.00
        12 | East      | 46673113.00
        22 | East      | 48711211.00
        24 | East      | 48603836.00
        31 | East      | 46836469.00
        36 | East      | 48461449.00
        37 | East      | 48018279.00
        41 | East      | 48713084.00
        44 | East      | 47808362.00
        49 | East      | 46990023.00
        50 | East      | 47643329.00
         9 | MidWest   | 46851087.00
        15 | MidWest   | 48787354.00
        27 | MidWest   | 48497620.00
        29 | MidWest   | 47639234.00
        30 | MidWest   | 49013483.00
        38 | MidWest   | 48856012.00
        42 | MidWest   | 47297912.00
        45 | MidWest   | 48544521.00
        46 | MidWest   | 48887255.00
         4 | NorthWest | 47580215.00
        39 | NorthWest | 47136892.00
        47 | NorthWest | 48477574.00
         8 | South     | 48131455.00
        13 | South     | 47605422.00
        17 | South     | 46054367.00
...
(50 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
  </channel>
</rss>
