MySQL 查询值列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8945538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:25:50  来源:igfitidea点击:

MySQL Query a List of Values

mysql

提问by JMC

I want to create a query from a list of values and return data for every match of cat.

我想从值列表中创建一个查询,并为cat.

This works but it's not requiring the optionsvalue. What's the easier way to query a list of values?

这有效,但不需要该options值。查询值列表的更简单方法是什么?

SELECT * 
FROM `table1` 
WHERE `option`='R' && `cat`='12' || `cat`='18' || `cat`='30'

回答by Shraddha

You can use the INoperator

您可以使用IN运算符

`cat` IN ('12', '18', 30')

回答by Sergio Tulentsev

You probably forgot to enclose those ORparts into parentheses

您可能忘记将这些OR部分括在括号中

SELECT * 
FROM `table1` 
WHERE `option`='R' and (`cat`='12' or `cat`='18' or `cat`='30')