NinjaKlown
NinjaKlown

Reputation: 61

How to just return the email host in a single sql statement

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

Answers (2)

Payer Ahammed
Payer Ahammed

Reputation: 907

I try this in MySQL:

SELECT SUBSTRING_INDEX(SUBSTR(emails, INSTR(emails, '@') + 1), '.', 1)
FROM Studentemails

Upvotes: 0

Sateesh Pagolu
Sateesh Pagolu

Reputation: 9606

 select substr(emails, INSTR(emails,'@')+1,INSTR(emails,'.')-INSTR(emails,'@')-1)
from Studentemails;

Upvotes: 1

Related Questions