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. Can you use HAVING without GROUP BY?

    Yes. Without GROUP BY, the whole table is treated as one group, so HAVING can filter that single aggregate row. If the condition is false, the query returns no rows.

    IntermediateQuick answer1 min read
  2. What does GROUP BY ROLLUP do?

    ROLLUP adds subtotal and grand-total rows to a grouped result. For GROUP BY ROLLUP(a, b) you get rows for (a, b), then a subtotal per a, then one grand total, with NULL marking the rolled-up columns.

    IntermediateQuick answer1 min read
  3. Write a query to find the highest-paid employee in each department.

    Compute MAX(salary) per department in a subquery and join back, or use RANK() OVER (PARTITION BY dept ORDER BY salary DESC) and keep rank 1. Both return all tied employees.

    IntermediateQuick answerCoding1 min read