0

I have a table with e-mailaddresses, which are all like redir.IDENTIFIER@redirthis.url

How can I run a query which only selects the identifier?

Table emails

+----+--------------------------------+
| id | email                          |
+----+--------------------------------+
|  1 | [email protected]     |
|  2 | [email protected]     |
|  3 | [email protected] |
+----+--------------------------------+

Expected/desired result

+----+------------+
| id | email      |
+----+------------+
|  1 | A73283     |
|  2 | XAAX83     |
|  3 | A73283F3GH |
+----+------------+

1 Answer 1

1

You can use substring_index for this if the pattern is same

mysql> select substring_index(substring_index('[email protected]','@',1),'.',-1);
+-----------------------------------------------------------------------------+
| substring_index(substring_index('[email protected]','@',1),'.',-1) |
+-----------------------------------------------------------------------------+
| A73283                                                                      |
+-----------------------------------------------------------------------------+

So the query would be

select 
id,
substring_index(substring_index(email,'@',1),'.',-1) as email
from emails
Sign up to request clarification or add additional context in comments.

Comments

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.