Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Distinct Values Query

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

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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results