AnalystPath

Second Most Expensive Book Price

SQLMediumMid level~15 min

Problem

A bookshop tracks the listed price of every title it sells.

Table: `catalog_titles`

| Column | Type |
|-------------|------|
| title_id | int |
| list_price | int |

`title_id` is the primary key. Each row is the listed price (in whole shekels) of one book in the catalog.

Write a query that returns the **second highest distinct** `list_price` in the catalog, aliased as `runner_up_price`. If there is no such second distinct price, the query must return `NULL`.

Example

With prices 40, 55 and 72, the second highest distinct price is 55.

Tables

Example rows — the live problem includes the full dataset.

catalog_titles
title_idlist_price
140
272
355

Expected output

Your answer should return 1 row with the columns runner_up_price.

Starter code (SQL)

SELECT *
FROM catalog_titles;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions