

現在有兩張表。 表A和表B。
A表,有個欄位叫做:ID。
B表,有個欄位叫做:current_address。
現在想做個”like 子查詢“,即
select * from b where current_address like '% 表A.ID %'
uj5u.com熱心網友回復:
但怎么寫都不對啊。 有大神嘛 ~ 求指點uj5u.com熱心網友回復:
select a.*,b.* from A a,B b where b.current_address like concat('%',a.ID,'%');uj5u.com熱心網友回復:
兩個表連接,條件就寫b表的current_address like '% 表A.ID %'就ok了啊uj5u.com熱心網友回復:
select B.current_address from A表inner join B表 on B.current_address like concat('%',A表.id,'%');
uj5u.com熱心網友回復:
select distinct(B.current_address) from B表inner join A表 on B.current_address like concat('%',A表.id,'%');
uj5u.com熱心網友回復:
select b.* from a,b where b.current_address = concat(‘/artices/’,a.id)uj5u.com熱心網友回復:
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左邊百分號,這樣可以用到索引
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/36831.html
標籤:MySQL
上一篇:將兩張表關聯怎么根據material_coding的值找到對應的表進行修改
下一篇:postgreSQL匯總比較慢。
