By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,903 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

Search fails when criteria includes an underscore

Claus Mygind
100+
P: 571
The following where clause returns data not wanted.
Expand|Select|Wrap|Line Numbers
  1. select * from <someTable> where <Column1> like "%Lamp_I%" or <Column2> like "%Lamp_I%"
  2.  
My sample data should have returned one row but instead it returned all rows whether it had an underscore or a blank.

sample data looked like this

12 records had the following "Lamp Inc." in <Column1>

one of the 12 records contained "Lamp_I" in <Column2>

How can I prevent returning records that are not like the criteria submitted when an underscore is included?
Jan 7 '13 #1

✓ answered by Anas Mosaad

Claus,
I'm not sure I'm understanding the question correctly or not. However, underscore is a special character in MySQL that mean any character (one single character). To escape it, prefix it with \ character (i.e. "%Lamp\_I%")

Share this Question
Share on Google+
3 Replies


100+
P: 185
Claus,
I'm not sure I'm understanding the question correctly or not. However, underscore is a special character in MySQL that mean any character (one single character). To escape it, prefix it with \ character (i.e. "%Lamp\_I%")
Jan 7 '13 #2

Claus Mygind
100+
P: 571
You understood me perfectly. That is what I needed to know. Thanks
Jan 14 '13 #3

100+
P: 185
You are always welcome :-)
Jan 17 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.