← All SQL interview questions

Second highest invoice amount

MediumSubqueriesPayPalOracle

A billing dashboard shows the runner-up invoice as a sanity check against the largest one.

From invoices, return a single column second_highest_amount containing the second highest distinct amount. If fewer than two distinct amounts exist the query should return NULL rather than no rows.

Sample data

Table: invoices

12 row(s) · showing first 8

invoice_idINTaccount_codeTEXTissued_onDATEamountNUMERIC(12,2)
1AC-9002026-01-0348200.00
2AC-9012026-01-07126500.00
3AC-9022026-01-1291000.00
4AC-9032026-01-18126500.00
5AC-9042026-01-2433750.50
6AC-9052026-02-01108900.00
7AC-9062026-02-0615400.00
8AC-9072026-02-1172300.00

Practising alone only goes so far — our live cohorts pair SQL depth with dashboards, agentic analytics projects and mock interviews.

Explore the program