How can I make SQL case sensitive string comparison on MySQL?

前端 未结 11 2407
温柔的废话
温柔的废话 2020-11-22 02:45

I have a function that returns five characters with mixed case. If I do a query on this string it will return the value regardless of case.

How can I make MySQL stri

11条回答
  •  庸人自扰
    2020-11-22 03:21

    Instead of using the = operator, you may want to use LIKE or LIKE BINARY

    // this returns 1 (true)
    select 'A' like 'a'
    
    // this returns 0 (false)
    select 'A' like binary 'a'
    
    
    select * from user where username like binary 'a'
    

    It will take 'a' and not 'A' in its condition

提交回复
热议问题