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