MySQL LIKE IN()?

2018-12-31 07:24发布

My current query looks like this:

SELECT * FROM fiberbox f WHERE f.fiberBox LIKE '%1740 %' OR f.fiberBox LIKE '%1938 %' OR f.fiberBox LIKE '%1940 %'

I did some looking around and can't find anything similar to a LIKE IN() - I envision it working like this:

SELECT * FROM fiberbox f WHERE f.fiberbox LIKE IN('%140 %', '%1938 %', '%1940 %')

Any ideas? Am I just thinking of the problem the wrong way - some obscure command I've never seen.

MySQL 5.0.77-community-log

标签: sql mysql
10条回答
还给你的自由
2楼-- · 2018-12-31 08:01

Sorry, there is no operation similar to LIKE IN in mysql.

If you want to use the LIKE operator without a join, you'll have to do it this way:

(field LIKE value OR field LIKE value OR field LIKE value)

You know, MySQL will not optimize that query, FYI.

查看更多
只若初见
3楼-- · 2018-12-31 08:03

Just a little tip:

I prefer to use the variant RLIKE (exactly the same command as REGEXP) as it sounds more like natural language, and is shorter; well, just 1 char.

The "R" prefix is for Reg. Exp., of course.

查看更多
冷夜・残月
4楼-- · 2018-12-31 08:05

This would be correct:

SELECT * FROM table WHERE field regexp concat_ws("|",(
"111",
"222",
"333"
));
查看更多
像晚风撩人
5楼-- · 2018-12-31 08:13

Regexp way with list of values

SELECT * FROM table WHERE field regexp concat_ws("|",
"111",
"222",
"333");
查看更多
登录 后发表回答