简体   繁体   中英

how to select a row where one of several columns equals a certain value?

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?

除非我在这里遗漏了什么......

SELECT * FROM MYTABLE WHERE COLUMNA=MyValue OR COLUMNB=MyValue OR COLUMNC=MyValue

I prefer this way as its neater

select *
from mytable
where
myvalue in (ColumnA, ColumnB, ColumnC)
SELECT *
FROM myTable
WHERE (Column1 = MyOtherValue) AND
      ((ColumnA = MyValue) OR (ColumnB = MyValue) OR (ColumnC = MyValue))

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM