MySQL IN clause EITHER value

370 views Asked by At

I have this query:

SELECT 1 IN (1,2)

Which returns 1 since 1 is inside (1,2).

What I want to do is check if either one of two values exists in the array. In an imaginary world:

SELECT (3,1) EITHER IN (1,2)

Something like this should return 1 since at least one value was found in the second array. Of course this query is incorrect. Is there a way to do this and avoid this:

SELECT (
   3 IN (1,2)
   OR
   1 IN (1,2)
)
1

There are 1 answers

0
overflowed On BEST ANSWER

you can use an inner join for that

select a, b form T1
inner join T2 on (T1.a = T2.c or T1.b = T2.c)