Binary Select In Join Statement
Moderator: General Moderators
-
WanamakerStudios
- Forum Commoner
- Posts: 65
- Joined: Thu Nov 30, 2006 7:35 am
Binary Select In Join Statement
Anyone know how to do a BINARY select in a JOIN statement?
-
WanamakerStudios
- Forum Commoner
- Posts: 65
- Joined: Thu Nov 30, 2006 7:35 am
As far as I remember, any valid expression not involving aggregate function is allowed as a join condition, i.e.
Code: Select all
select ...
from table1
inner join table2
on cast(table1.field as binary) = cast(table2.field as binary)
...
-
WanamakerStudios
- Forum Commoner
- Posts: 65
- Joined: Thu Nov 30, 2006 7:35 am
MySQL manual wrote: The CAST() and CONVERT() functions take a value of one type and produce a value of another type.
[...]
The BINARY operator casts the string following it to a binary string.[...]Code: Select all
mysql> SELECT 'a' = 'A'; -> 1 mysql> SELECT BINARY 'a' = 'A'; -> 0 mysql> SELECT 'a' = 'a '; -> 1 mysql> SELECT BINARY 'a' = 'a '; -> 0
BINARY str is shorthand for CAST(str AS BINARY).