tags:

views:

66

answers:

3

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.

A: 

Have a look at using

UPPER and LOWER

astander
+4  A: 

Use UPPER

SELECT * FROM USER WHERE UPPER(U.NAME) = 'STEVEN'
Nivas
it is not worked in search like when i use like condition
steven spielberg
@InSane, for the example, if the name in the table is sTEVEN, the above SQL would work. 'STEVEN' in the SQL, I assume is something like a search parameter, so we can force that to be upper always.
Nivas
@steven, can you give an example, where it is not working?
Nivas
try to check them in like when your column set as utf unicode and try with both lower and upper case
steven spielberg
@Nivas - i was referring to the parameter value having 'sTEVEN' - but like you said, if u use the above query, the search parameter has to be forced to be upper ... just somewhere else! That's fair enough!! just that it should be noted - for completeness..thats all!
InSane
WHERE email LIKE '%gmail%' try with it
steven spielberg
@steven, an example please, of the SQL, what is in the table that is not returned in the result of the sql...
Nivas
@InSane, agreed.
Nivas
@steven, when you say `where upper(email) like ('%GMAIL%)`, and there is a `[email protected]` in the table, you don't get it in the results?
Nivas
you'd better delete your answer as wrong and misleading
Col. Shrapnel
@Col. Shrapnel I dont get you...
Nivas
Properly configured database performing case insensitive search BY DEFAULT. By applying a function to a field contents you will disable index usage. with obvious consequences.
Col. Shrapnel
@Col. Shrapnel, yes. But what if I want both? (Almost) all cases not case sensitive, but just ont little search (for a report, say) that needs to search case sensitive....
Nivas
USE COLLATION. That's what collations are for
Col. Shrapnel
+5  A: 

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.

Jonathon
+1, fixing it on the column is preferable to using UPPER/LOWER
Unreason
Good answer at last.
Col. Shrapnel