Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Unified Profile With Latest Attributes

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

Your question is SQL Unified Profile With Latest Attributes. Start with the requirements and the three 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

Write a SQL query to combine customer records from multiple tables and return a unified profile with the latest attributes at Acxiom.

Use the provided customer master, profile history, and preference history tables. Return every customer, including customers without matching history records.

Output

  1. One row per customer with customer_id, external_id, first_name, last_name, email, phone, preferred_channel, marketing_opt_in, profile_updated_at, and preference_updated_at.
  2. Use the latest profile and preference record for each customer; retain NULLs when no matching record exists.
  3. Order by customer_id ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTStable customer identifier
external_idVARCHAR(20)Acxiom external customer identifier
customer_profile_history
ColumnTypeDescription
profile_idPKINTProfile history record identifier
customer_idINTReferenced customer
first_nameVARCHAR(80)Customer first name
last_nameVARCHAR(80)Customer last name
emailVARCHAR(255)Customer email address
phoneVARCHAR(30)Customer phone number
updated_atTIMESTAMPProfile version timestamp
customer_preference_history
ColumnTypeDescription
preference_idPKINTPreference history record identifier
customer_idINTReferenced customer
preferred_channelVARCHAR(20)Preferred communication channel
marketing_opt_inBOOLEANMarketing consent status
updated_atTIMESTAMPPreference version timestamp
Tablescustomerscustomer_profile_historycustomer_preference_history
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results