2dbi

SQL Fundamentals and Query Writing

viaLeetCode

Prompt SQL round: concept questions on database fundamentals followed by writing real queries.

Be ready to discuss

  • Keys and constraints: primary vs unique vs foreign keys, NOT NULL/CHECK/DEFAULT, referential actions (CASCADE/SET NULL).
  • Indexes: B-tree basics, when an index helps vs hurts (write overhead, low-selectivity columns), composite index column order, covering indexes.
  • Joins: INNER vs LEFT/RIGHT vs FULL, join vs subquery, and NULL pitfalls in joins and comparisons.
  • Aggregation: GROUP BY semantics, HAVING vs WHERE, window functions (ROW_NUMBER/RANK, running totals).
  • Typical queries to write on the spot: second-highest salary, top-N per group (window + filter), duplicate detection (GROUP BY … HAVING count > 1), employees without a manager (LEFT JOIN … IS NULL), department-wise averages.
Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account