473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

LIKE syntax problem

Hello,

I try to develop a query to match wildcards following the LIKE
guidline in the MySQL manual
(http://dev.mysql.com/doc/mysql/en/pattern-matching.html)

Who can help me solve the matching problem? The string I am looking
for consists of 2 charachters a capital B folowed by one digit not
neccesarilly at the beginning of the record.
However it does not return results when it should in my opinion do so.
See the following sample:

SELECT firstname
FROM `patient`
WHERE firstname LIKE '%B[0-9]%' LIMIT 10

returns:

nothing

SELECT firstname
FROM `patient`
WHERE firstname LIKE '%B_[0-9]%' LIMIT 10

returns:

nothing

SELECT firstname
FROM `patient`
WHERE firstname LIKE '%B[0-9]_%' LIMIT 10

returns:

nothing

whereas the following statement

SELECT firstname
FROM `patient`
WHERE firstname LIKE '%B%' LIMIT 10

returns:

+-------------------+
| firstname |
+-------------------+
| B1O1V2 LM |
| B102v3ap |
| B. |
| B. |
| HUBERTINA |
| Tobben |
| B1O1V2 LI LAT LOK |
| B1o1v2 Lm |
| Boost |
| B1o1v1 Ml |
+-------------------+

What am I doing wrong? Or is this only supported by MySQL version 4.1
and up or something like that? I'm running MySQL version 4.0.22-nt-max
on a MS Windows 2000 server environment.

Thanks!

Jonathan
Jul 23 '05 #1
4 6118

No, this is not MySQL 4+ only, but your syntax is wrong. Compare with:

http://dev.mysql.com/doc/mysql/en/regexp.html

e.g.

SELECT firstname
FROM `patient`
WHERE firstname REGEXP '%B[0-9]_%' = 1
LIMIT 10

---
Steve

Jul 23 '05 #2
On 24 Jan 2005 09:32:35 -0800, "Steve" <go********@nastysoft.com>
wrote:

No, this is not MySQL 4+ only, but your syntax is wrong. Compare with:

http://dev.mysql.com/doc/mysql/en/regexp.html

e.g.

SELECT firstname
FROM `patient`
WHERE firstname REGEXP '%B[0-9]_%' = 1
LIMIT 10

---
Steve


Thanks for the hint. It should be this way I believe:

SELECT firstname
FROM `patient`
WHERE firstname REGEXP '[b][0-9][V][0-9]' = 1

The % and _ placeholders/wildcards resulted in error messages.

Jonathan
Jul 23 '05 #3
X-No-Archive: yes

Oops, sorry, should have looked more closely. Glad you have it working
now.

---
Steve

Jul 23 '05 #4
Jonathan wrote:
WHERE firstname REGEXP '%B[0-9]_%' = 1

Regular expressions and SQL LIKE expressions each come from different
heritage.

Character ranges such as [0-9] are not treated as metacharacters in LIKE
expressions in SQL. The only wildcards in LIKE expressions are % and _.
Conversely, the % and _ characters have no special meaning in regular
expressions.
WHERE firstname REGEXP '[b][0-9][V][0-9]' = 1


For what it's worth, this could be written equivalently as:
WHERE firstname REGEXP 'B[0-9]V[0-9]'
A character range of [b] is the same as simply a literal B.

Regards,
Bill K.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
16
by: George Sakkis | last post by:
I'm sure there must have been a past thread about this topic but I don't know how to find it: How about extending the "for <X> in" syntax so that X can include default arguments ? This would be very...
2
by: Craig Stadler | last post by:
Im trying to write a like query select * from table1 where column1 like 'abc%' (I realize this syntax isnt correct) I want to include any chars from 0-9 in that spot... Does anyone know how...
122
by: seberino | last post by:
I'm interested in knowing which Python web framework is most like Ruby on Rails. I've heard of Subway and Django. Are there other Rails clones in Python land I don't know about? Which one...
3
by: bearophileHUGS | last post by:
Psyco is finished now, and it works on the x86, for Win, the new macs, many linux boxes, etc, and it's quite useful, so maybe it can be added to the standard Python distribution. PyChecker (and...
21
by: Dmitry Anikin | last post by:
I mean, it's very convenient when default parameters can be in any position, like def a_func(x = 2, y = 1, z): ... (that defaults must go last is really a C++ quirk which is needed for overload...
2
by: redcic | last post by:
Hi all, I would like to build a xml file using Xerces. I know how to build a single node at a time. For example, with 'doc' belonging to the DocumentImpl class and with 'docRootNode' belonging...
29
by: dbhbarton | last post by:
Had a thought that's grown on me. No idea if it's original or not- too inexperienced in programming- but I guess there's no harm floating it out there. Python wins big on readability, and...
2
enfuego
by: enfuego | last post by:
Hey kids, got a problem. Here's the code: Rev.techCompany CASE WHEN techCompany LIKE 'North_IR' THEN 'NorthIR' WHEN techCompany LIKE 'South_IR' THEN 'SouthIR' WHEN techCompany LIKE...
151
by: istillshine | last post by:
There are many languages around: C++, JAVA, PASCAL, and so on. I tried to learn C++ and JAVA, but ended up criticizing them. Is it because C was my first programming language? I like C...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.