← All SQL interview questions

Third highest salary in every department

HardSubqueriesOracleWalmartEXL

Compensation benchmarking needs the third highest distinct salary inside each department.

From payroll_records, return department and third_highest_salary. Departments with fewer than three distinct salaries must be omitted entirely.

Sample data

Table: payroll_records

16 row(s) · showing first 8

record_idINTemployee_nameTEXTdepartmentTEXTsalaryINT
1Ira BansalAnalytics1900000
2Devansh RaoAnalytics1750000
3Nikhil SarinAnalytics1600000
4Mahima SethiAnalytics1600000
5Yusuf AliAnalytics1400000
6Prerna IyerEngineering2400000
7Sagar NaikEngineering2100000
8Rhea KapoorEngineering1850000

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

Explore the program