Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Get Duplicate Emails Query

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Get Duplicate Emails Query. Start with the requirements and the two tables on the right.

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.

Problem

Ion's Wallstreet Suite client-account data may contain duplicate contact email addresses. Write a PostgreSQL query that identifies normalized email addresses appearing more than once among contacts linked to active client accounts.

Requirements

  1. Join client_contacts to client_accounts using account_id.
  2. Treat email addresses case-insensitively and ignore leading or trailing spaces.
  3. Exclude NULL emails and accounts that are not ACTIVE.
  4. Return the normalized email and its duplicate count, ordered by count descending and email ascending.

Schema

client_contacts
ColumnTypeDescription
contact_idPKINTUnique contact identifier
account_idINTIdentifier of the linked client account
full_nameVARCHAR(100)Contact's full name
email_addressVARCHAR(255)Contact email address
client_accounts
ColumnTypeDescription
account_idPKINTUnique client account identifier
account_codeVARCHAR(30)Wallstreet Suite account code
account_statusVARCHAR(20)Current lifecycle status of the account
Tablesclient_contactsclient_accounts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results