“in”语句中的多个列(mysql)

时间:2016-11-30 13:14:25

标签: mysql sql where

请告诉我如何实现这个SQL查询:

select * from products where (category, category2, category3) in (2, 138, 136, 125)

错误:

#1241 - Operand should contain 3 column(s)

3 个答案:

答案 0 :(得分:1)

只需在where子句中写下所有列,如下所示:

SELECT *
FROM products
WHERE
  category IN (2, 138, 136, 125) OR
  category2 IN (2, 138, 136, 125) OR
  category3 IN (2, 138, 136, 125)

答案 1 :(得分:1)

select * from products 
where category in (2, 138, 136, 125)
      OR 
      category2 in (2, 138, 136, 125)
      OR
      category3 in (2, 138, 136, 125)

答案 2 :(得分:1)

嗯,这是你打算做的吗?

select * from products where category in (2, 138, 136, 125)
                         AND category2 in (2, 138, 136, 125)
                         AND category3 in (2, 138, 136, 125)

OR,取决于要求。