views:

28

answers:

3

in my table ,

I have firstname and last name ,

few names are upper case ,( ABRAHAM )

few names are lower case ,(abraham)

few names are character starting with ucword (Abraham)

So when i am doing the where condition using REGEXP '^[abc]' ,am not getting proper records,

How to change the names to lower case and use SELECT QUERY ,

SELECT * FROM `test_tbl` WHERE cus_name REGEXP '^[abc]';

This is my query, works fine if the records are lower case, but my records are intermediate ,my all cus name are not lower case , all the names are like ucword ,

So for this above query am not getting proper records display ,

+1  A: 

I think you should query your database making sure that the names are lowered, suppose that name is the name you whish to find out, and in your application you've lowered it like 'abraham', now your query should be like this:

SELECT * FROM `test_tbl` WHERE LOWER(cus_name) = name

Since i dont know what language you use, I've just placed name, but make sure that this is lowered and you should retrieve Abraham, ABRAHAM or any variation of the name!

Hepe it helps!

David Conde
REGEXP '^[[:<:]]b.*[[:>:]]' this rendering the records name starting with b but if i add or condition then it displaying REGEXP '^[[:<:]]b.*|c.*[[:>:]]' all records , that is starting with what ever like f,t,h,u but as per my condition it should render only starts with b and c character names,
Bharanikumar
A: 

You don't need regexp to search for names starting with a specific string or character.

SELECT * FROM `test_tbl` WHERE cus_name LIKE 'abc%' ; 

% is wildcard char. The search is case insensitive unless you set the binary attribute for column cus_name or you use the binary operator

SELECT * FROM `test_tbl` WHERE BINARY cus_name LIKE 'abc%' ; 
aeon
your query searches for names starting with the string 'abc' something very different from OP's query which searches for names beginning with either 'a' or 'b' or 'c'.
codaddict
i guess above is wrong , we should se REGEXP '^[ABC]'
Bharanikumar
I assumed the user was trying to build a "search as you type" field/tool.
aeon
A: 

Have you tried:

SELECT * FROM `test_tbl` WHERE LOWER(cus_name) REGEXP '^[abc]';
codaddict