How do I create a select all statement that checks multiple columns in a single row for one value and if it doesn't have the value then exclude it from the query?
Asked
Active
Viewed 203 times
0
-
Can you share some sample data and the result you're trying to achieve? It's a bit hard to follow what you're trying to do. – Mureinik Nov 13 '14 at 18:26
-
Possible duplicate: [questions/13916400/checking-multiple-columns-for-one-value](https://stackoverflow.com/questions/13916400/checking-multiple-columns-for-one-value). – Ryan Vincent Nov 13 '14 at 18:29
-
1Do all columns have to have that value or at least one? – Andrew Nov 13 '14 at 18:30
2 Answers
6
You can do this pretty simply by reversing the normal in
operator: value in (column1, column2, column3)

Allan
- 17,141
- 4
- 52
- 69
-
Ah this got it! Thanks Allan! Yeah I haven't used sql in awhile, still a little rusty! – derekjs67 Nov 13 '14 at 18:59
1
Use a "reversed" IN():
select ....
from ...
where someValue in ( col1, col2, col3, ...)

Bohemian
- 412,405
- 93
- 575
- 722