system0102
system0102

Reputation: 169

MySQL: Select values containing only one digit

Let's say I have a column with emails:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
test23test.com

How can I select only those that contains only one digit?

Result should be:

[email protected]
[email protected]
[email protected]

I tried:

REGEXP '[[:digit:]]{1}' and REGEXP '[0-9]{1}' but it shows all results that contain AT LEAST one digit

Upvotes: 1

Views: 336

Answers (2)

zzxx53
zzxx53

Reputation: 423

If you don't specify number of repetitions, it is one copy by default. Try something like

REGEXP '(^[0-9]+)([0-9])@.+'

Upvotes: 0

Iłya Bursov
Iłya Bursov

Reputation: 24146

try to use ^[^0-9]*[0-9]{1}[^0-9]*$

Upvotes: 2

Related Questions