Example

Teradata Vantageā„¢ SQL Functions, Expressions, and Predicates

brand
Software
Teradata Vantage
prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1145-162K

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);