[英]MYSQL Left Join returning all rows that match the first character
I've got a simple left join in a MYSQL environment. 我在MYSQL环境中有一个简单的左连接。
SELECT *
FROM (`holiday`)
LEFT JOIN `member` ON `member`.`memberId` = `holiday`.`memberId`
ORDER BY `holiday`.`begin_date` ASC
However instead of returning only exact matches it is returning any records where the member.memberId has the holiday.memberId in the first character. 但是,它不是仅返回完全匹配,而是返回member.memberId在第一个字符中具有holiday.memberId的任何记录。
Results: 结果:
holidayId holiday.memberId member.memberId
9 1 1
9 1A65152F 1
10 1 1
10 1A65152F 1
How do I get it to just return the exact matches? 如何让它返回完全匹配?
The field holiday.memberId
is a STRING, while member.memberId
is a INTEGER, so MySQL automatically casts the string to a Number (eg "123ABC" will be converted to 123). 领域holiday.memberId
是一个字符串,而member.memberId
是一个整数,因此MySQL的自动转换的字符串的数字(例如“123ABC”将被转换为123)。
You could try this: 你可以试试这个:
SELECT *
FROM (`holiday`)
LEFT JOIN `member` ON `member`.`memberId` = BINARY `holiday`.`memberId`
ORDER BY `holiday`.`begin_date` ASC
Using BINARY it will force a binary comparison, disabling the automatic cast. 使用BINARY将强制进行二进制比较,禁用自动转换。
Or you should convert both fields to string. 或者您应该将两个字段都转换为字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.