简体   繁体   English

MySQL:LIKE子句中的Select语句

[英]MySQL: Select statement in a LIKE clause

I want to use " like '%(selected result)%' " phrase. 我想使用" like '%(selected result)%' "短语。 Below code is mine 下面的代码是我的

 where note like '%(SELECT ds_word.ds_en FROM ds_word
                     WHERE ds_co LIKE '%콜레라%' LIMIT 0 ,1)%'

But '%~~~%' use make an error, that is, 但是'%~~~%'使用会产生错误,即

"#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(SELECT code_co.code, code_co.disease_co, code_en.disease_en FROM code_co LEFT' at line 44". “#1064-您的SQL语法有误;请在与MySQL服务器版本相对应的手册中找到正确的语法,以在'(SELECT code_co.code,code_co.disease_co,code_en.disease_en FROM code_co LEFT'附近使用44“。

How can i use that expression? 我如何使用该表达方式? Help me, please! 请帮帮我!

And, below answer outputs the result picture. 并且,下面的答案输出结果图片。 在此处输入图片说明 This is the captured picture on phpmyadmin. 这是在phpmyadmin上捕获的图片。

WHERE note LIKE
CONCAT ('%',(SELECT ds_word.ds_en FROM ds_word WHERE ds_co LIKE '%콜레라%' LIMIT 0 ,1), '%')

What I think is, Since you are trying to use a value inside your LIKE statement, you will need to modify it to something like: 我的想法是,由于您尝试在LIKE语句中使用值,因此需要将其修改为:

where note like CONCAT('%',SELECT ds_word.ds_en FROM ds_word WHERE ds_co LIKE '%콜레라%' LIMIT 0 ,1, '%')

Hope this works for you. 希望这对您有用。

Use \\ to escape the ' which is the escape character 使用\\转义'是转义字符

where note 
like '%(SELECT ds_word.ds_en FROM ds_word WHERE ds_co LIKE \'%콜레라%\' LIMIT 0 ,1)%';

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

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