Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Extract Domain From Emails
00:00
5 left

Extract Domain From Emails

EasySQL · PostgreSQL

Problem

Write a SQL query to extract the domain name from a column containing raw email addresses.

Use the email_records table and handle leading or trailing whitespace, mixed-case addresses, NULL values, and malformed entries.

Output

  1. One row per valid email record, with columns id, raw_email, and domain_name.
  2. Exclude NULL, blank, and malformed email values.
  3. Normalize domains to lowercase and order results by id ascending.

Schema

email_records
ColumnTypeDescription
idPKINTUnique email record identifier
raw_emailVARCHAR(255)Raw email address, which may contain whitespace, mixed case, or invalid values
Tablesemail_records
Interviewer

Your question is Extract Domain From Emails. Start with the requirements and the one table in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.