user989990
user989990

Reputation: 175

Does MySQL support a number or digit wildcard pattern?

I want to select titles that have a number after a certain character. Example:

SELECT * FROM table WHERE title LIKE '%- H(any number)'

How would I select any number in this statement 1-10000000 if the number exists?

Upvotes: 10

Views: 14604

Answers (3)

Eugen Rieck
Eugen Rieck

Reputation: 65304

SELECT * FROM table WHERE title RLIKE '- H[:digit:]{1,7}$';

will give you 1-9999999

Upvotes: 4

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324750

SELECT * FROM table WHERE title REGEXP '.*- H[0-9]+'

That seems like the kind of thing you're looking for.

Upvotes: 9

ruakh
ruakh

Reputation: 183456

Use a regular expression:

SELECT ...
  FROM table
 WHERE title REGEXP '- H([1-9][0-9]{0,6}|10000000)$'
;

Upvotes: 1

Related Questions