mySQL查询选择列,其中value = a或value = b等

时间:2014-03-20 19:47:17

标签: mysql

如何编写mysql查询,以便我可以在列下选择等于resultA或resultB或resultC等的条目。

类似的东西:

SELECT * FROM myTable WHERE myColumn = resultA OR WHERE myColumn = resultB OR WHERE myColumn = resultC...

4 个答案:

答案 0 :(得分:9)

SELECT *
FROM myTable
WHERE myColumn = 'resultA' 
   OR myColumn = 'resultB' 
   OR myColumn = 'resultC';

可替换地,

SELECT *
FROM myTable
WHERE myColumn IN ('resultA', 'resultB', 'resultC');

答案 1 :(得分:1)

多次使用WHERE,只需在条件之间使用OR

SELECT * 
FROM myTable 
WHERE myColumn = 'resultA'
OR myColumn = 'resultB'
OR myColumn = 'resultC'

请注意,我将resultX用单引号包围,假设它们是字符串,如果它们是整数,则可以省略它们

答案 2 :(得分:1)

这应该有用。

SELECT * FROM myTable WHERE myColumn = 'resultA' OR myColumn = 'resultB' OR myColumn = 'resultC'

答案 3 :(得分:1)

SELECT * FROM myTable WHERE myColumn in (resultA, resultB, resultC ....)