0

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

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

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 [email protected] 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 ?

3
  • @zerkms: Yeah regex to parse emails in format NEWUSER(\d+)@domain.com where \d is a number you know but it doesn't return any rows obviously regex isn't correct Commented Sep 13, 2013 at 11:35
  • You want the last line ? i mean largest number will always at the last line ? Commented Sep 13, 2013 at 11:38
  • @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 Commented Sep 13, 2013 at 11:39

1 Answer 1

1
 SELECT * FROM tableName where email like 'NEWUSER%' ORDER BY CAST(SUBSTR(email FROM 8) AS UNSIGNED) desc limit 1
Sign up to request clarification or add additional context in comments.

5 Comments

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 [email protected]
This only works when the email address pattern is always the same. It breaks when there are addresses like [email protected]
You want sort numerals only? [email protected]
@jey: I only want to get rows with NEWUSER term in email field
@Dev01:SELECT * FROM tables where website like 'NEWUSER%' ORDER BY CAST(SUBSTR(website FROM 8) AS UNSIGNED) desc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.