我有两张 table
USERS 包含用户数据
手机
447777744444
447777755555
7777755555
7777766666
MOBILEPHONES 包含手机号码
电话
7777744444
7777733333
7777755555
7777766666
如果我运行以下 SQL,它只会返回完全匹配的数字,并且不会执行通配符搜索。
SELECT MobilePhones.*, users.FirstName FROM MobilePhones
LEFT JOIN users
ON (users.MobilePhone= MobilePhones.`Telephone No`)
WHERE users.MobilePhone LIKE CONCAT('%', MobilePhones.`Telephone No`, '%')
我回来了
7777755555
7777766666
我想要的是
7777755555
7777766666
447777755555
447777744444
最佳答案
我认为您可能希望将 WHERE
子句移动到连接的 ON
子句中,替换现有的 ON
子句,即做完全匹配:
SELECT MobilePhones.*, users.FirstName
FROM MobilePhones
LEFT JOIN users ON users.MobilePhone LIKE CONCAT('%', MobilePhones.`Telephone No`, '%')
关于mysql - 使用 LIKE 和 CONCAT % 比较两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10637339/