Skip to content
Advertisement

What is the proper term for one of the disjuncts in a query using UNION?

Complete the sentence: In the query

SELECT 0 UNION ALL SELECT 1;

the sub-selects SELECT 0 and SELECT 1 are properly known as the ___________s of the UNION.

I am not looking for your opinion on what would be a good name – I want you to back your answer up with a reference to some kind of authoritative source.

Advertisement

Answer

If I understand the Standard SQL document correctly this seems to be called <query term>.

It’s hard to find SQL:20xx online, Itzik Ben-Gan shows the relevant part in Fundamentals of table expressions

7.17 <query expression>
 

Function
Specify a table.
 

Format
  <query expression> ::=
    [ <with clause> ] <query expression body>
      [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
  <with clause> ::=
    WITH [ RECURSIVE ] <with list>
  <with list> ::=
    <with list element> [ { <comma> <with list element> }… ]
  <with list element> ::=
    <query name> [ <left paren> <with column list> <right paren> ]
      AS <table subquery> [ <search or cycle clause> ]
  <with column list> ::=
    <column name list>
  <query expression body> ::=
      <query term>
    | <query expression body> UNION [ ALL | DISTINCT ]
        [ <corresponding spec> ] <query term>
    | <query expression body> EXCEPT [ ALL | DISTINCT ]
        [ <corresponding spec> ] <query term>
  <query term> ::=
      <query primary>
    | <query term> INTERSECT [ ALL | DISTINCT ]
        [ <corresponding spec> ] <query primary>
  <query primary> ::=
      <simple table>
    | <left paren> <query expression body>
        [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
        <right paren>
  <simple table> ::=
      <query specification>
    | <table value constructor>
    | <explicit table>
  <explicit table> ::=
    TABLE <table or query name>
  <corresponding spec> ::=
    CORRESPONDING [ BY <left paren> <corresponding column list> <right paren> ]
  <corresponding column list> ::=
    <column name list>
  <order by clause> ::=
    ORDER BY <sort specification list>
  <result offset clause> ::=
    OFFSET <offset row count> { ROW | ROWS }
  <fetch first clause> ::=
    FETCH { FIRST | NEXT } [ <fetch first quantity> ] { ROW | ROWS } { ONLY | WITH TIES }
  <fetch first quantity> ::=
      <fetch first row count>
    | <fetch first percentage>
  <offset row count> ::=
    <simple value specification>
  <fetch first row count> ::=
    <simple value specification>
  <fetch first percentage> ::=
    <simple value specification> PERCENT
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement