Mysql 使用LIKE和CONCAT%比较两个表格

Mysql 使用LIKE和CONCAT%比较两个表格,mysql,pattern-matching,sql-like,concat,Mysql,Pattern Matching,Sql Like,Concat,我有两张桌子 用户包含用户数据 移动电话 4477744444 4477755555 777775555 777776666 手机包含手机号码 电话号码 777774444 7777733333 777775555 777776666 如果我运行followsql,它只返回完全匹配的数字,而不执行通配符搜索 SELECT MobilePhones.*, users.FirstName FROM MobilePhones LEFT JOIN users ON (users.MobilePhone=

我有两张桌子

用户包含用户数据

移动电话
4477744444
4477755555
777775555
777776666

手机包含手机号码

电话号码
777774444
7777733333
777775555
777776666

如果我运行followsql,它只返回完全匹配的数字,而不执行通配符搜索

SELECT MobilePhones.*, users.FirstName FROM MobilePhones
LEFT JOIN users
ON (users.MobilePhone= MobilePhones.`Telephone No`)
WHERE users.MobilePhone LIKE CONCAT('%', MobilePhones.`Telephone No`, '%')
我回来了

777775555
777776666

我想要的是

777775555
777776666
4477755555

447777744444

我认为您可能希望将您的
WHERE
子句移动到join的
ON
子句中,替换现有的
ON
子句,该子句正在进行精确匹配:

SELECT MobilePhones.*, users.FirstName 
FROM MobilePhones
LEFT JOIN users ON users.MobilePhone LIKE CONCAT('%', MobilePhones.`Telephone No`, '%')

我认为您可能希望将
WHERE
子句移动到join的
ON
子句中,替换现有的
ON
子句,该子句正在进行精确匹配:

SELECT MobilePhones.*, users.FirstName 
FROM MobilePhones
LEFT JOIN users ON users.MobilePhone LIKE CONCAT('%', MobilePhones.`Telephone No`, '%')