471,108 Members | 1,279 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Like query syntax question

Im trying to write a like query

select * from table1 where column1 like 'abc[0-9]%'
(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
cs********@hotmail.com
Jul 20 '05 #1
2 3914
Im trying to write a like query

select * from table1 where column1 like ’abc[0-9]%’
(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
cs********@hotmail.com
Craig,

The elegant way of solving your problem is with regular expressions.
Search for "mysql regex" using a search engine.

Otherwise you have to write:

like ’%abc1%’ or like ’%abc2%’ ....

yikes!

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/mySQL-query-...ict140719.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=471490
Jul 20 '05 #2
Craig Stadler wrote:
Im trying to write a like query

select * from table1 where column1 like 'abc[0-9]%'
(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?


Standard SQL expressions used with the LIKE predicate have only two
wildcards: '_' matches a single character (like '.' in UNIX-style
regular expressions), and '%' matches any sequence of characters (like
'.*' in UNIX-style regular expressions)

MySQL extends SQL with a predicate that matches more complex regular
expressions, including many of the wildcards familiar to UNIX users.

In your example, you should be able to get the result you want with the
following query:
select * from table1 where column1 REGEXP '^abc[0-9]'

See also:
http://dev.mysql.com/doc/mysql/en/Pattern_matching.html
http://dev.mysql.com/doc/mysql/en/Regexp.html

Regards,
Bill K.
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Craig Stadler | last post: by
6 posts views Thread by T. Wintershoven | last post: by
10 posts views Thread by Daniel | last post: by

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.