在MySQL中将LIKE%..%与字段值一起使用 [英] Use LIKE %..% with field values in MySQL

查看:496
本文介绍了在MySQL中将LIKE%..%与字段值一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我需要使用LIKE%..%语句中的字段中的值时,我偶然遇到了一个精致的SQL问题.

I stumbled into a delicate SQL problem when I needed to use a value from a field inside a LIKE %..% statement.

示例:

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

这只是我脑海中的一个例子,它显示了我需要做的事情(我知道这是行不通的).我需要在LIKE%..%

This is only 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 value of t2.Name inside the LIKE %..%

我想这很简单;)

推荐答案

使用:

SELECT t1.Notes, 
       t2.Name
  FROM Table1 t1
  JOIN Table2 t2 ON t1.Notes LIKE CONCAT('%', t2.Name ,'%')

这篇关于在MySQL中将LIKE%..%与字段值一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆