Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Name Formatting Query

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

Your question is SQL Name Formatting Query. Start with the requirements and the one table 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

Optum's member directory export stores a member's name in a single full_name column. Write a PostgreSQL query that formats each valid name for display in the form Last, First.

Requirements

  1. Split each nonblank full_name into first and last name components.
  2. Return the formatted name as formatted_name, preserve missing or blank names as NULL, and sort alphabetically with null values last.

Assume each populated name contains a first name and a last name separated by whitespace. Extra spaces should not affect the result.

Schema

members
ColumnTypeDescription
member_idPKINTEGERUnique member identifier
full_nameVARCHAR(150)Member's first and last name
Tablesmembers
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results