tags:

views:

61

answers:

4

Say I have a table that includes column A, column B and column C. How do I write I query that selects all rows where either column A OR column B OR column C equals a certain value? Thanks.

Update: I think forgot to mention my confusion. Say there is another column (column 1) and I need to select based on the following logic:

...where Column1 = '..' AND (ColumnA='..' OR ColumnB='..' OR ColumnC='..')

Is it valid to group statements as I did above with parenthesis to get the desired logic?

+3  A: 

Unless I'm missing something here...

SELECT * FROM MYTABLE WHERE COLUMNA=MyValue OR COLUMNB=MyValue OR COLUMNC=MyValue
Eric J.
+2  A: 
SELECT *
FROM myTable
WHERE (Column1 = MyOtherValue) AND
      ((ColumnA = MyValue) OR (ColumnB = MyValue) OR (ColumnC = MyValue))
Degan
+2  A: 

I prefer this way as its neater

select *
from mytable
where
myvalue in (ColumnA, ColumnB, ColumnC)
David Raznick
+2  A: 

Yes, it's valid to use parentheses. However, if you're searching multiple columns for the same value, you may want to consider normalizing the database.

Bruce Alderman
+1, I completely missed that! ColumnA-ColumnB-ColumnC threw me off, if it were emailA-EmailB-EmailC it would have been more obvious
KM