I just had a need to search a particular string value in 2 columns, so my usual approach is
SELECT ... FROM ...
WHERE (col1 = 'xyz' OR col2 = 'xyz')
But if I had to check multiple values (just for a quick check), say once for 'abc', then 'www', then 'lol', and so on, it is a pain.
So, I tried this and it worked! I never knew this syntax was supported.
SELECT ... FROM ...
WHERE 'xyz' IN (col1, col2)
Is it ok to use this way? I mean are there any caveats?
X IN (A, B, C)
gets expanded toX = A OR X = B OR X = C
, which, together with the symmetry of=
, allows you to establish equivalency easily. The only thing to avoid (but that's true in both cases) is mixing types in the expressions, since implicit conversions can have surprising results. – Chet