473,799 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6131

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********@nas tysoft.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
17794
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. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
16
2611
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 useful for list/generator comprehensions, for example being able to write something like: instead of the less elegant explicit loop version that has to check for the length of each sequence. What do you think ? George
2
716
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 to do this? -Craig cstadler18@hotmail.com
122
7924
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 has largest community/buzz about it?
3
1308
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 the other similar ones that work differently) is very useful too, and it's pure Python, so maybe it too (or something similar) can be added to the standard distribution. --------------------
21
2340
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 resolution, isn't it?) and when calling, just omit parameter when you want to use defaults: a_func(, , 3)
2
2163
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 to the ElementNSImpl class, I do: myElement = doc.createElement('elementName') docRootNode.appendChild(myElement)
29
2377
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 there's no doubt that context- dependent text formatting in IDEs (keywords, strings, comments etc) is a massive help too, therefore benefitting development and maintenance. This idea is in a similar vein, especially for when scripts grow large.
2
5233
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 'East_IR' THEN 'EastIR' WHEN techCompany LIKE 'North_' THEN 'NorthContractor' WHEN techCompany LIKE 'South_' THEN 'SouthContractor' WHEN techCompany LIKE 'East_' THEN 'EastContractor' END AS Region From xxx.reviews AS Rev GROUP BY...
151
8135
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 because, comparatively, it is small, efficient, and able to handle large and complex tasks. I could not understand why people are using and talking about other programming languages.
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.