In SQLite, if I type:
SELECT (SELECT 1 UNION SELECT 2 UNION SELECT 3) INTERSECT SELECT 3 UNION SELECT 4
I get the result 4
. How is that possible?
SELECT 1 UNION SELECT 2 SELECT 3
is (1, 2, 3)
, right? And SELECT 3 UNION SELECT 4
is (3, 4)
. So, the intersect should be 3
, right? What am I getting wrong?
EDIT: Saying that INTERSECT
is evaluated first does not answer my question, as ((1,2,3) INTERSECT (3)) UNION (4)
is (3,4)
, rather than 4
.