Use LIKE% ..% with field values ​​in MySQL

I came across a subtle SQL problem when I needed to use a value from a field inside a LIKE% ..% statement.

Example:

SELECT t1.Notes, t2.Name FROM Table1 t1, Table2 t2 WHERE t1.Notes LIKE '%t2.Name%' 

This is just an example from the top of my head to show what I need to do (I know this will not work). I need to use the t2.Name value inside LIKE% ..%

I think this is trivial when you know it;)

+49
sql mysql sql-like
Dec 12 2018-12-12T00:
source share
2 answers

Using:

 SELECT t1.Notes, t2.Name FROM Table1 t1 JOIN Table2 t2 ON t1.Notes LIKE CONCAT('%', t2.Name ,'%') 
+108
Dec 12 '10 at 5:44
source share
  SELECT t1.a, t2.b FROM t1 JOIN t2 ON t1.a LIKE '%'+t2.b +'%' 

because the last answer does not work

-one
Jul 27. '16 at 10:23
source share



All Articles