SQL Playground
TutorialsPlayground
SQL FormatterSQL MinifierSyntax ValidatorJSON to SQLCSV to SQLSQL to JSONER Diagram Generator
Daily ChallengeInterviewsCheat SheetBlog

© 2026 SQL Playground. Built for developers.

PrivacyTermsAboutRSS Feed
SQL Playground
TutorialsPlayground
SQL FormatterSQL MinifierSyntax ValidatorJSON to SQLCSV to SQLSQL to JSONER Diagram Generator
Daily ChallengeInterviewsCheat SheetBlog
Back to Pool
Airbnb

Second Highest Salary

Write a query to find the second highest salary from the Employee table. If there is no second highest salary, return NULL.

Schema

SQL Editor
Loading...

Execution Result

Write and run your query to see results here.

Problem Context & Learning

💡Why This Question Matters

This classic interview question tests your understanding of aggregate functions and subqueries. Airbnb frequently uses this to assess candidates' ability to handle ranking and filtering operations, which are common in their pricing and availability systems. The challenge lies in handling edge cases: what if there's only one unique salary? What if all salaries are the same? Your solution must gracefully return NULL in these scenarios.

🔑Key SQL Concepts

This problem primarily tests: MAX() aggregate function, nested subqueries for comparison, handling NULL values when no second highest exists, and understanding DISTINCT for duplicate handling. Alternative approaches include ORDER BY with LIMIT/OFFSET or window functions like DENSE_RANK().

🌍Real-World Applications

In production systems, similar queries are used for: finding the second-best pricing option for dynamic pricing algorithms, identifying runner-up candidates in recommendation systems, analyzing performance metrics where you need to exclude the top outlier, and calculating fallback values in availability searches when the primary option is unavailable.

Interview Insights & Approach

Strategic Approach

When tackling this Airbnb problem, the key is to understand the grain of the result. Are you returning one row per user, or one row per category? Always start by identifying your unique join keys and consider if filtered aggregations (CASE WHEN) are more efficient than multiple subqueries.

Common Pitfalls

Be careful with NULL values in your JOIN conditions or aggregate functions. In interview scenarios, datasets often include edge cases like zero-count categories or duplicate entries that can throw off a simple COUNT(*) if not handled with DISTINCT.

Discussion & Solutions

Share your approach, optimized queries, or ask questions. Learning from others is the fastest way to master SQL.

💬 Join the conversation below

Comments

© 2026 SQL Playground. Built for developers.

PrivacyTermsAboutRSS Feed