1. 程式人生 > >mysql 兩張表字段模糊匹配--字串拼接函式

mysql 兩張表字段模糊匹配--字串拼接函式

concat(A,B,C,...)  拼接字串

例如concat('123','***','345')  =>123***345

SELECT
    concat(
        substr(t1.CODE, 1, 3),
        '****',
        substr(t1.CODE, 8)
    ),
    t1.CODE,
    t2.TITLEFROM
    table1 t1LEFT JOIN table2 t2 ON t1.table2id = t2.idWHERE
    t1..CREATEDATE >= '
2016-07-19 00:00:00'AND t1.CREATEDATE <= '2016-07-19 23:59:59';

兩張表字段模糊匹配,進行資料更新:

update tb1 join tb2 on tb1.a like concat('%',tb2.a,'%')
set tb1.xx=tb2.xx
where xxx;