Example - Analytics Database - Teradata Vantage

SQL Functions, Expressions, and Predicates

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-01-12
dita:mapPath
obm1628111499646.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
kby1472250656485
lifecycle
latest
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);