“合并” Mysql 中的 IN 和 LIKE 运算符
我有一个问题,我猜测是否有更好的方法来实现我的目标。我在 Mysql 中有这个查询来检索一些行:
SELECT *
FROM table
WHERE field IN ('V','S','G','B')
我想做的是运行一个查询来检索字段具有类似于 IN 列表中的值的行。我知道最简单的方法是使用此查询:
SELECT *
FROM table
WHERE field LIKE '%V%' OR field LIKE '%S%' OR
field LIKE '%G%' OR field LIKE '%B%'
我想知道是否有一个运算符可以执行此操作,或者至少,如果该运算符不存在,则有更好的方法来编写查询。
感谢所有帮助我的人。
I've a problem and I'm guessing if there's a better way to achieve my goal. I've this query in Mysql to retrieve some rows:
SELECT *
FROM table
WHERE field IN ('V','S','G','B')
What I would like to do is to run a query that retrieve the rows where the field has value LIKE those in the IN list. I know that the trivial way is to use this query:
SELECT *
FROM table
WHERE field LIKE '%V%' OR field LIKE '%S%' OR
field LIKE '%G%' OR field LIKE '%B%'
What I want to know is there's an operator that do this or at least, if that operator does not exist, a better way to write the query.
Thanks to everyone that will help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将值放入表 (
Params
) 中,然后使用请考虑将通配符放入
Params
表中的值中。Put the values in a table (
Params
) then useConsider also putting the wildcard characters into the values in the
Params
table.