There are several working solutions, but I see no explanation why they work, and your attempt does not work.
The IN statement wants to get a list of values โโto check. In the simplest case, it looks like a WHERE column IN (value1, value2, value3...) . It also works with SELECT : WHERE column IN (SELECT somecolumn FROM sometable) .
The query does not return a single column that can be used as a list, but three different columns. This is not the correct syntax for the IN statement. G Mastros uses the UNION operator to combine three different select queries into one, one column, the result set.
(In principle, I would use UNION ALL in this case, since duplicate values โโare not a problem, and UNION is a slower operation. But check your clientโs statistics, as checking multiple copies of values โโmay be a higher leak than UNION )
StuffHappens uses the UNPIVOT operator to get the same behavior as splitting the three required columns into a single result set. Personally, I would go with UNION , mainly because the syntax of UNPIVOT harder to understand.
source share