Memory Jogger: Case Insensitve and “Like” MySQL queries.

Another one I keep having to remind myself how to do. If you want to do case insensitive SQL queries than just convert both target field and the string to the same case.

SELECT * FROM ‘tableName’ WHERE UCASE(‘columnName’) =  UCASE(“targetString”)

If you want to use wild cards than use LIKE and % for wild cards.

SELECT * FROM ‘tableName’ WHERE ‘columnName’ LIKE “%targetString%”

You can of course combine the two:

SELECT * FROM ‘tableName’ WHERE UCASE(‘columnName’) LIKE  UCASE(“%targetString%”)

Just a quick taster. If you want to know more than try looking at the MySQL entry here:

http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html

Related Posts:

This entry was posted in Memory Joggers and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>