mySQL regex seleccionando cadena y número incremental

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 desde 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 ?

preguntado el 13 de septiembre de 13 a las 12:09

@zerkms: Yeah regex to parse emails in format NEWUSER(\d+)@domain.com sin que importe \d is a number you know but it doesn't return any rows obviously regex isn't correct -

You want the last line ? i mean largest number will always at the last line ? -

@Jageen: not necessaly it will always be last line, it could be anywhere but i want to get row with largest number in email. I have updated the question -

1 Respuestas

 SELECT * FROM tableName where email like 'NEWUSER%' ORDER BY CAST(SUBSTR(email FROM 8) AS UNSIGNED) desc limit 1

Respondido el 13 de Septiembre de 13 a las 13:09

well it works with warnings but still not ideal solution since it doesn't consider my explicit string NEWUSER and therefore may also return incorrect rows such as ABCDEFG3@domain.com - Dev01

This only works when the email address pattern is always the same. It breaks when there are addresses like NEWGROUP1@domain.com - Wietze314

You want sort numerals only? hjfhgkhdf45@jfdhgj.com - Vaishu

@jey: I only want to get rows with NEWUSER term in email field - Dev01

@Dev01:SELECT * FROM tables where website like 'NEWUSER%' ORDER BY CAST(SUBSTR(website FROM 8) AS UNSIGNED) desc - Vaishu

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.