-1

I'm practicing exercises with SQL and I've got a problem I couldn't resolve yet.

I have a table with a column named: **'email' ** and I want to extract just the Domain of each mail. Then I was thinking to extract since '@' to get that information.

But idk how to do it, was trying with SUBSTRING, but that didn't work because that's about position, and each mail has different size.

I attach a screenshot about the table's composition (does not contain real information). Thank u so much :)

enter image description here

I tried with SUBSTRING method but that didn't work Example email: example_email@outlook.com Output expected: @outlook.com

Fernanda
  • 25
  • 1
  • 4
  • `mysql` and `postgresql` are completely different databases, using different syntax for (at least) some functions. Please only specify the DBMS you are actually using. – Luuk Dec 09 '22 at 17:10
  • Please show the statement that you where (trying) to use. – Luuk Dec 09 '22 at 17:10
  • Does this answer your question? [SQL Get char at position in field](https://stackoverflow.com/questions/1409822/sql-get-char-at-position-in-field) – Luuk Dec 09 '22 at 17:12
  • Hmmz, it should have been this post which is making this a duplicatie: [MYSQL : Find the last occurrence of a character in a string](https://stackoverflow.com/questions/44276940/mysql-find-the-last-occurrence-of-a-character-in-a-string) – Luuk Dec 09 '22 at 17:17

1 Answers1

0

We can use SPLIT_PART to fetch everything after the @ and then append the @:

SELECT CONCAT('@',SPLIT_PART(email, '@', 2)) AS mailDomain
FROM people_practice;

Here the documentation about this and other useful string functions.

Jonas Metzler
  • 4,517
  • 1
  • 5
  • 17