Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top N SQL Query

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

Your question is Top N SQL 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 get the 3rd largest number.

Use the number_values table and treat duplicate values as one value. Ignore NULL values. Return no row when fewer than three distinct non-null numbers exist.

Output

  1. Return one column named third_largest_number.
  2. Return exactly one row containing the third largest distinct non-null value.
  3. Sort values from largest to smallest before identifying the result.

Schema

number_values
ColumnTypeDescription
idPKINTUnique identifier for the stored number
number_valueNUMERICNumber considered for ranking
Tablesnumber_values
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results