简体   繁体   English

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

[英]Multiple Columns in an “in” statement (mysql)

Can you please advise how i can implement this sql query: 你能告诉我如何实现这个SQL查询:

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

Error: 错误:

#1241 - Operand should contain 3 column(s)

Simply write all columns in where clause like this: 只需在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)
select * from products 
where category in (2, 138, 136, 125)
      OR 
      category2 in (2, 138, 136, 125)
      OR
      category3 in (2, 138, 136, 125)

Mmm, is this what you intended to do? 嗯,这是你打算做的吗?

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 with OR , depends on the requirement . 或者使用OR ,取决于要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM