#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    56
    Rep Power
    3

    SQL Case Insensitive Search


    Can you please tell me how I can do the following search but make it case insensitive?

    Code:
    SELECT * FROM dp_user WHERE user_name = 'Carlos';
    Empty set (0.00 sec)
    I want to be able to find either 'Carlos' or 'carlos' in my SQL statement but I can't find anything on Google that shows me how to correct my SQL statement...
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,147
    Rep Power
    4274
    which database system are you using?

    you posted in the "database management" forum, which is this site's catch-all forum for database systems which don't have their own specific forum, namely DB2, MySQL, Postgresql, Firebird, Microsoft SQL Server, and Oracle

    without knowing which database system you're running, it's very hard to solve specific issues, such as case sensitivity
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    56
    Rep Power
    3
    I'm using PostgreSQL and at times I have two systems that run MySQL.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,784
    Rep Power
    348
    Code:
    SELECT * 
    FROM dp_user 
    WHERE lower(user_name) = lower('Carlos');
    Note that this will prevent usage of an index on the user_name column, so for large tables this will be quite inefficient.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    56
    Rep Power
    3
    How is that command different from:

    Code:
    SELECT * 
    FROM dp_user
    WHERE lower(user_name) = 'carlos';

IMN logo majestic logo threadwatch logo seochat tools logo