2006
01.23

MySQL Collation for UNION

Let say you want to create a on-the-fly table which fetch the list of users with certain properties. The problem with the users is that, some of them is without any properties. Instead of displaying blank, you want to display ‘—-‘. Since you want to do this on the fly, not by modifying the table. These infos will come handy.

Simply using UNION will help you to achieve above problem. Meta-SQL :

Select User,Properties 
From Users where Properties <> Null 
Union 
Select User, '----' as Properties 
From users 
where User not in 
(Select User from Users where Properties <> Null)

In IIS, this will throw you Collation error if you Users table is encoded in UTF8, the Properties value of ‘—-‘ will be encoded in Latin. Thus, it will throws you collation error.

In order to convert the ‘—-‘ encoded as UTF8, you must use _utf8 as prefix of your string. Eq: _utf8′—-‘ instead of only ‘—-‘

GD Star Rating
loading...
Worth sharing ?

Incoming Search Term

Advertise Here

 

No Comment

Add Your Comment