htshame
htshame

Reputation: 7330

Substring after last dot

In my MySQL I have a table user. There's an email field.

Some emails have many dots in them, e.g.: [email protected]

I'd like to select everything after last dot. In case of the email above it'll be com.

So far I've came up only with:

 SELECT RIGHT(email, LOCATE('.', email) - 1) FROM user;

but it seems to trim only after the first dot.

Upvotes: 2

Views: 563

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269873

Use substring_index():

select substring_index(email, '.', -1) as suffix
from user;

Upvotes: 4

Related Questions