15.00 - Set Operators in INSERT … SELECT Statements - Teradata Database

Teradata Database SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Content Type
Programming Reference
Publication ID
B035-1145-015K
Language
English (United States)

Set Operators in INSERT … SELECT Statements

Set operators are permitted in INSERT … SELECT statements. The following examples demonstrate their correct use.

Example  

The first example demonstrates a simple INSERT … SELECT using set operators.

      INSERT table1 (x1,y1)
      SELECT * 
      FROM table_2
      UNION
      SELECT x3,y3 
      FROM table_3;

Example  

The second example demonstrates an INSERT … SELECT from a view that uses set operators.

      REPLACE VIEW v AS
      SELECT * 
      FROM table_1
      UNION
      SELECT * 
      FROM table_2;
      
      INSERT table_3(x3,y3)
      SELECT * 
      FROM v;

Example  

This example demonstrates an INSERT … SELECT from a derived table with set operators.

      INSERT table_1
      SELECT * 
      FROM
      (SELECT x2,y2 
      FROM table_2
      UNION
      SELECT * 
      FROM table_3 DerivedTable
      );