TC
Company prep
TCS
Fresher (0–1 years)
Coding / DSA
Easy
Write a SQL query to find the second highest salary from an Employee table
Standard SQL screening question for 0–1 year candidates.
Model answer
Try answering aloud first
Cover trade-offs, structure, and a concrete example before revealing the baseline response.
Spoiler-free prep mode
SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);Alternatives: DENSE_RANK() OVER (ORDER BY salary DESC) and filter rank = 2; or OFFSET 1 LIMIT 1 on distinct salaries (DB-specific).
Mention NULL when fewer than two distinct salaries exist.
Discussion
Comments (0)
Share how this question came up in your loop, or add tips for others preparing.
Log in to comment on this question.