我正在尝试为Mysql运行php Where命令,但我想要做的是从同一列中选择2个值,例如:
reviews_table - id,收件人,海报,评论
SELECT * FROM reviews_table WHERE recipient = 'business 1' (But also recipient = business 2) LIMIT = 12
如何正确地实现这一目标?
答案 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