MYSQL如何进行sql like (sql查询结果)的查询

我有个需求,需要在MYSQL下like查询另一条sql查询的结果,大概格式如下:
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 中函数, 用于连接字符串的。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值