mySQL regex seleccionando cadena y número incremental

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

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 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+)'

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+) 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 - Dev01

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

You want sort numerals only? - 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.