Search code examples
sqlsqlitecase-sensitive

Case sensitive like select SQLite


So I have the following query:

select username from users where username like 'aDam%'

but the problem here is that its not case sensitive. this query will get also users named 'adam%', 'Adam%', etc..

Question: How do I get only 'aDam%' (make the query case sensitive)?

note: the % operator is important here.


Solution

  • Since Like is case insensitive it will not work on its own but one workaround is to use it together with the SUBSTR function

    select username 
    from users 
    where username like 'aDam%' 
      and substr(username,1,4) = 'aDam'