How to select a row where one of several columns is equal to a certain value?

Say I have a table that includes column A, column B, and column C. How do I write a query I that selects all rows where either column A OR column B or column C is equal to some value? Thanks.

Update: I forgot to mention my confusion. Let's 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 for grouping statements, as I did above, with parentheses to get the desired logic?

+3
source share
4

- ...

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

,

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

Yes, it is valid for using parentheses. However, if you are looking for multiple columns for the same value, you might want to normalize the database.

+2
source

Source: https://habr.com/ru/post/1715741/


All Articles