在同一列上使用多个Select Where语句

时间:2013-09-19 13:07:47

标签: php mysql select where

我正在尝试为Mysql运行php Where命令,但我想要做的是从同一列中选择2个值,例如:

  

reviews_table - id,收件人,海报,评论

SELECT * FROM reviews_table WHERE recipient = 'business 1' (But also recipient = business 2) LIMIT = 12

如何正确地实现这一目标?

4 个答案:

答案 0 :(得分:2)

您可以使用IN子句

SELECT * FROM reviews_table 
WHERE recipient IN ('business 1', 'business 2')
LIMIT = 12

对于这种情况。

我建议IN子句使用OR进行单独检查,因为˛WHERE子句通常由多个条件组成,与AND连接,条件为{ {1}}他们之间需要注意大括号,不要造成不良后果。

一个缺点是您无法使用OR ...

进行LIKE '%whatever'比较

答案 1 :(得分:0)

使用OR之类的

SELECT * FROM reviews_table 
WHERE recipient = 'business 1' 
OR recipient = 'business 2'
LIMIT = 12

答案 2 :(得分:0)

只需使用OR:

SELECT * FROM reviews_table WHERE recipient = 'business 1' OR recipient = 'business 2' LIMIT = 12

答案 3 :(得分:0)

SELECT *
FROM `reviews_table`
WHERE `recipient` IN ('business 1','business 2') 
LIMIT = 12