Example - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-30
dita:mapPath
tpt1555966086716.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantageā„¢

To select rows of t1 whose values in column x1 are equal to the value in column x2 of t2, one of the following queries can be used:

   SELECT * 
   FROM t1 
   WHERE x1 IN 
    (SELECT x2 
     FROM t2);
   SELECT * 
   FROM t1 
   WHERE EXISTS 
    (SELECT * 
     FROM t2 
     WHERE t1.x1=t2.x2);

To select rows of t1 whose values in column x1 are not equal to any value in column x2 of t2, you can use any one of the following queries:

   SELECT * 
   FROM t1 
   WHERE x1 NOT IN 
    (SELECT x2 
     FROM t2);
   
   SELECT * 
   FROM t1 
   WHERE NOT EXISTS 
    (SELECT * 
     FROM t2 
     WHERE t1.x1=t2.x2);
   
   SELECT 'T1 is not empty' 
   WHERE EXISTS 
    (SELECT * 
     FROM t1); 
   
   SELECT 'T1 is empty' 
   WHERE NOT EXISTS 
    (SELECT * 
     FROM t1);