Reputation: 61
I am trying to figure out how to return just the host name in an email address in a single SQL statement.
For example if I have
[email protected]
it should return
gmail
I have this SQL code:
select substr(emails, INSTR(emails, '@') + 1)
from Studentemails;
this returns gmail.com
So how do I get rid of the .com
?
Upvotes: 0
Views: 52
Reputation: 907
I try this in MySQL:
SELECT SUBSTRING_INDEX(SUBSTR(emails, INSTR(emails, '@') + 1), '.', 1)
FROM Studentemails
Upvotes: 0
Reputation: 9606
select substr(emails, INSTR(emails,'@')+1,INSTR(emails,'.')-INSTR(emails,'@')-1)
from Studentemails;
Upvotes: 1