我有个需求,需要在MYSQL下like查询另一条sql查询的结果,大概格式如下:
select * from table1 where `text` like '%(select name from table2 where id =3)%';
请问如何才是正确格式?谢谢
select * from table1 where `text` like '%(select name from table2 where id =3)%';
请问如何才是正确格式?谢谢
正确答案已出:使用CONCAT SQL语句为:select * from table1 where `text` like CONCAT('%',(select name from table2 where id =3),'%'); 感谢没有留名的热心网友,我看在网上问这个问题的不少,但都没有正确答案 ************************************ 感谢大家的热心,不过请大家在回答前最好自己试下能否在MYSQL下通过 我总结下几种不能达到效果的SQL 1:select * from table1 where `text` like (select name from table2 where id =3); 2:select * from table1 where `text` like '%'(select name from table2 where id =3)'%'; 3:select * from table1 where `text` like '%' + (select name from table2 where id =3) +'%'; 4:select * from table1 where `text` like '%(select name from table2 where id =3)%'; 5:select * from table1 where `text` like '%’select name from table2 where id =3‘%'; 6:select * from table1 where `text` like '%( select name from table2 where id =3 ) +'%';(第二条SQL单独占一行)最佳答案SELECT * FROM table1 WHERE `text` LIKE CONCAT( '%', (SELECT NAME FROM table2 WHERE id = 3 ), '%' ); 这样看看,行么 ? CONCAT 是 mysql 中函数, 用于连接字符串的。