mysql like 子查询

JeremyChenX 2019-09-24 10:23:11




现在有两张表。 表A和表B。

A表,有个字段叫做:ID。

B表,有个字段叫做:current_address。

现在想做个”like 子查询“,即

select * from b where current_address like '% 表A.ID %'
...全文
439 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdn_castiel 2019-12-09
  • 打赏
  • 举报
回复
select * from b where current_address like concat('/artices/','表A.ID%') union all select * from b where current_address like concat('/其他路径/','表A.ID%') union all select * from b where current_address like concat('/其他路径2/','表A.ID%') 。。。 删掉like左边百分号,这样可以用到索引
蜕变之痛 2019-10-04
  • 打赏
  • 举报
回复
select b.* from a,b where b.current_address = concat(‘/artices/’,a.id)
有点意思! 2019-09-27
  • 打赏
  • 举报
回复
select distinct(B.current_address) from B表 inner join A表 on B.current_address like concat('%',A表.id,'%');
有点意思! 2019-09-27
  • 打赏
  • 举报
回复
select B.current_address from A表 inner join B表 on B.current_address like concat('%',A表.id,'%');
JeremyChenX 2019-09-24
  • 打赏
  • 举报
回复
但怎么写都不对啊。 有大神嘛 ~ 求指点
听雨停了 2019-09-24
  • 打赏
  • 举报
回复
两个表连接,条件就写b表的current_address like '% 表A.ID %'就ok了啊
张蒙炬 2019-09-24
  • 打赏
  • 举报
回复
select a.*,b.* from A a,B b where b.current_address like concat('%',a.ID,'%');

56,802

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧