2

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

Some emails have many dots in them, e.g.: firstname.lastname.smth.else@example.com

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
htshame
  • 6,599
  • 5
  • 36
  • 56

1 Answers1

4

Use substring_index():

select substring_index(email, '.', -1) as suffix
from user;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786