Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Distinct Values Query
00:00
5 left

SQL Distinct Values Query

EasySQL · PostgreSQL

Problem

Write a SQL query to find the distinct values in a column.

Use the records.category column. Include each unique non-NULL value and the NULL value if it exists.

Output

  1. One row per distinct category value
  2. Return the column as distinct_category
  3. Sort ascending, with NULL values last

Schema

records
ColumnTypeDescription
record_idPKINTUnique record identifier
categoryVARCHAR(100)Category value to inspect for distinct values
Tablesrecords
Interviewer

Your question is SQL Distinct Values Query. 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.