parliament
parliament

Reputation: 22964

SQL empty IN statement

What happens if I write the following query:

SELECT *
FROM table
WHERE name IN (select name from someotherTable where id = 3)

and the inner query (inside the IN statement) returns no result set

will the outer where automatically evaluate to True or to False?

Upvotes: 0

Views: 363

Answers (2)

Joachim Isaksson
Joachim Isaksson

Reputation: 181077

Let's test it;

CREATE TABLE TableA ( id INT );
INSERT INTO TableA VALUES (1);
CREATE TABLE TableB ( id INT );
SELECT * FROM TableA
  WHERE id IN (SELECT * FROM TableB);

(empty set)

Upvotes: 1

JSK NS
JSK NS

Reputation: 3446

This will return an empty set.

Upvotes: 6

Related Questions