Interview Q&A / SQL & DBMS

INTERVIEW Q&A · 69 QUESTIONS

SQL & DBMS interview questions

Joins, keys, normalisation, indexes and transactions for placement and backend interviews.

  1. Write an SQL query to find the second highest salary.

    Find the highest salary that is less than the maximum, with SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees). For the Nth highest, use DENSE_RANK() so that duplicate salaries share a rank, or ORDER BY DISTINCT salary with LIMIT and OFFSET.

    BeginnerIn-depthCoding3 min read
  2. How is a window function different from GROUP BY?

    GROUP BY collapses rows into one row per group. A window function computes an aggregate or rank over a set of related rows but keeps every original row in the output.

    BeginnerQuick answer1 min read