Search code examples
mysqlselectsql-likemysql-5.6

query two tables where one row is like another row


I need to join two tables where one row value should be inside the other row.

t1
f1,f2

t2
f11,f22

query
select * from t1 join t2 on f1=f11
where
f22 LIKE %f2%

How do I write this?


Solution

  • The correct syntax is:

    select *
    from t1 join
         t2
         on t1.f1 = t2f11
    where t2.f22 LIKE concat('%', t1.f2, '%')