Steven Spielberg
Steven Spielberg

Reputation:

How to search in MySQL in a case-insensitive way

How can I search for a user even if I don't know the exact spelling with regards to case, like

SELECT * FROM USER WHERE U.NAME =  'STEVEN';

Meaning: if a user has the name "Steven" or "sTEVEN" how can I search all persons who have this name?

I tried it, but it does not work.

WHERE email LIKE '%GMAIL%'

It did not not work when case was lowercase.

Upvotes: 1

Views: 167

Answers (3)

Jonathon Bolster
Jonathon Bolster

Reputation: 15961

The case sensitivity is based on the character set and collation of the table.

The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default.

http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html

You may want to look at the collation of your table if the searches are case-sensitive.

Upvotes: 5

Nivas
Nivas

Reputation: 18344

Use UPPER

SELECT * FROM USER WHERE UPPER(U.NAME) = 'STEVEN'

Upvotes: 3

Adriaan Stander
Adriaan Stander

Reputation: 166326

Have a look at using

UPPER and LOWER

Upvotes: 0

Related Questions