Usa COMO %..% con valores de campo en MySQL


Me topé con un delicado problema SQL cuando necesitaba usar un valor de un campo dentro de un %SIMILAR..% instrucción.

Ejemplo:

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

Esto es solo un ejemplo desde la parte superior de mi cabeza para mostrar lo que necesito hacer (sé que esto no funcionará). Necesito usar el valor de t2.Name dentro del MISMO porcentaje..%

Supongo que esto es trivial cuando lo sabes;)

Author: MPelletier, 2010-12-12

2 answers

Uso:

SELECT t1.Notes, 
       t2.Name
  FROM Table1 t1
  JOIN Table2 t2 ON t1.Notes LIKE CONCAT('%', t2.Name ,'%')
 113
Author: OMG Ponies,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-12 05:44:15
  SELECT t1.a, t2.b
  FROM t1
  JOIN t2 ON t1.a LIKE '%'+t2.b +'%'

Porque la última respuesta no funciona

 -3
Author: NT4.info,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-27 11:13:08