Extract domain name from email id

Question

Every email id is like

xyg@domain.com

 

 

in progress 0
TheDataMonk 3 years 7 Answers 983 views Grand Master 0

Answers ( 7 )

  1. ‘xyg@domain.com’.split(“@”)[1].split(“.”)[0]
    output->domain

  2. Where email is the column containing email id’s in the form of ‘abc@domain.com’ and domain is the table name (PGSQL)

    SELECT email,split_part(split_part(email,’@’,2),’.’,1)
    FROM domain;

  3. SELECT ID,
    SUBSTRING ([Email], CHARINDEX( ‘@’, [Email]) + 1,
    LEN([Email])) AS [answer]
    FROM email

  4. SELECT substring(email, CHARINDEX( ‘@’, [email]) + 1,
    LEN([email])) AS [Domain]
    From T;

  5. Using ‘mail’ as the column containing the email and ‘table’ as the table/

    select substr(email, charindex(‘@’,email)+1, len(email)) as domain_name
    from table

  6. Assuming the column of email ids as email_id and table name is customers
    SELECT email_id, split_part(email_id, ‘@’, 2) AS Domain
    FROM customers;

  7. Suppose we have two columns ‘ID’ and ‘Email’ in a table named ‘mail’. We need to extract the domain name from the mail ids.
    The following command can be used for the same.

    SELECT ( SUBSTRING_INDEX ( SUBSTR( Email, INSTR ( Email,’@’ ) + 1 ) ) , ‘.’ ,1) as Domain_name from mail ;

    INSTR(str1, str2) searches for str2 in str1 and gives the first position at which str1 occurs. ! has been added to t so that a position after the ‘@’ sign starts.
    SUBSTR( str, position) gives a substring of str starting from the inputted position.
    SUBSTRING_INDEX (str, delimiter, count) gives the substring from string str until the ‘count’ number of delimiter is seen.

Leave an answer

Browse
Browse