0

Hi so I have email addresses saved for example in below format:

NEWUSER1@domain.com
NEWUSER3@domain.com
NEWUSER2@domain.com

As can be seen everything is same in these email except for the number before @ sign. I want to select the last biggest email address with that number in this case NEWUSER3@domain.com since 3 is biggest number in these emails.

I am not much aware about regex but I tried this:

SELECT id, email FROM tableName WHERE email regexp 'NEWUSER(\d+)@domain.com'
ORDER BY email DESC LIMIT 1

But it didn't work obviously regex isn't correct :( Can anyone help on how to select row with biggest number email out of these please ?

4

1 回答 1

1
 SELECT * FROM tableName where email like 'NEWUSER%' ORDER BY CAST(SUBSTR(email FROM 8) AS UNSIGNED) desc limit 1
于 2013-09-13T11:45:11.893 回答