Now live Practical Business Analyst Course — launch price ₹999 ₹4,999 Enrol now
PM Codex
Free WhatsApp course Book a call
Courses Interview prep Company guides Portfolio builder Free WhatsApp course Salary calculator Blog
Business Analyst Technical BA easy

Write a SQL query to find the second-highest salary in an employees table.

Asked at InfosysTCSAccentureDeloitte
Framework

correlated subquery vs window function

Model answer

SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees); Or use DENSE_RANK() OVER (ORDER BY salary DESC) and filter rank = 2 — the ranked version handles ties correctly.

What great candidates actually do

  • The subquery approach fails on ties — mention this before they ask.
  • In interviews, always ask: 'Do duplicates count as the same rank?'
  • DENSE_RANK vs RANK vs ROW_NUMBER — know when to use each.

Unlock the model answer

Free. One email — unlocks every answer in the bank.

No spam. Unsubscribe anytime.

Traps to avoid

Related questions

Requirements

Walk me through the last BRD you wrote — how did you structure it?

Read answer →
Requirements

What's the difference between a BRD, FRD and SRS — and when would you use each?

Read answer →
Stakeholder

How would you elicit requirements from a senior stakeholder who won't give you time?

Read answer →
Practice with a human

Rehearse this out loud.

Book a 1:1 mock interview. Detailed feedback sheet + scoring on the exact rubric hiring managers use.

Book a mock interview