17.05 - Example - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Release Date
January 2021
Content Type
Programming Reference
Publication ID
B035-1146-175K
Language
English (United States)

In the next query, the SELECT order is reversed:

   SELECT level, param 'GMKSA CONTROL' (TITLE 'OWNER')
   FROM gmksa_control
   WHERE cycle = '03'
   UNION 
   SELECT level, param, 'GMKSA'
   FROM gmksa
   WHERE cycle = '03'
   ORDER BY 1, 2;

This query returns the following answer set:

   ***QUERY COMPLETED.10 ROWS FOUND. 3 COLUMNS RETURNED.
   LEVEL   PARAM     OWNER
   -----   -----     ------------- 
   00      A         GMKSA
   00      A         GMKSA CONTROL
   00      T         GMKSA
   00      T         GMKSA CONTROL
   85      X         GMKSA
   85      X         GMKSA CONTROL 
   SF      A         GMKSA
   SF      A         GMKSA CONTROL
   SF      T         GMKSA
   SF      T         GMKSA CONTROL

In this case, because the first SELECT specified ‘GMKSA CONTROL’, the rows were not duplicates and were included in the answer set.