SQLMentor // interview prep

SQL & Database Interview Questions

Free, no-signup interview preparation for SQL and database roles — real questions with detailed, worked answers, not flashcards. Each set below covers the questions you're most likely to be asked in technical screens and onsite interviews, with SQL you can copy straight into SQLMentor's free SQL editor and run.

These aren't generic trivia lists. Every answer explains the reasoning — why RANK() and DENSE_RANK() diverge on ties, why a correlated subquery differs from a JOIN, why NULL breaks a JOIN condition — because that's what interviewers actually probe for.

Interview question sets

Oracle SQL Interview Questions

15 of the most commonly asked SQL interview questions — WHERE vs HAVING, window functions, the Nth-highest-salary problem, correlated subqueries, deduplication, ACID, indexes, SQL injection, joins, normalization, CTEs, and NULL handling. Written for Oracle syntax but the concepts apply to any SQL dialect.

IBM DB2 Interview Questions

30 questions spanning beginner fundamentals through DBA-level troubleshooting — MERGE, isolation levels, RUNSTATS, clustering indexes, deadlocks, BLU Acceleration, and real scenario questions like "a query that ran in 200ms yesterday now takes 30 seconds."

Oracle PL/SQL Interview Questions

20 questions on Oracle's procedural language — block structure, %TYPE vs %ROWTYPE, implicit vs explicit cursors, exception handling, packages, triggers and the mutating-table error, BULK COLLECT/FORALL, autonomous transactions, and dynamic SQL.

PostgreSQL Interview Questions

16 questions covering what interviewers actually probe in PostgreSQL — MVCC, VACUUM & autovacuum, JSONB vs JSON, the index types (B-tree/GIN/GiST/BRIN), upserts with ON CONFLICT, LATERAL joins, isolation levels, and table partitioning.

SQL Server (T-SQL) Interview Questions

16 questions on the Microsoft stack — clustered vs non-clustered indexes, covering indexes, temp table vs table variable vs CTE, TRY...CATCH, MERGE, CROSS/OUTER APPLY, isolation levels & NOLOCK, IDENTITY vs SEQUENCE, and parameter sniffing.

SQL Interview Questions for Freshers

16 foundational questions pitched at 0-2 years of experience — SQL basics, primary/foreign keys, joins, DELETE vs TRUNCATE vs DROP, normalization, and NULL handling, explained simply.

SQL Interview Questions for Experienced Professionals

14 scenario-based questions for 5+ year engineers — diagnosing a slow query, resolving a production deadlock, partitioning strategy, zero-downtime migrations, and code-review judgment calls.

How to use these question sets

Frequently asked questions about SQL interviews

What is the difference between WHERE and HAVING?
WHERE filters individual rows before grouping; HAVING filters groups after aggregation. If your filter condition references an aggregate function like SUM or COUNT, it must go in HAVING.
What is the difference between RANK(), DENSE_RANK(), and ROW_NUMBER()?
All three number rows in an ordered set but handle ties differently: ROW_NUMBER() always gives unique sequential numbers, RANK() gives tied rows the same number and then skips the next rank, DENSE_RANK() gives tied rows the same number with no gap in the sequence.
How do you find the Nth highest salary in SQL?
The most flexible approach uses DENSE_RANK() in a subquery: SELECT DISTINCT salary FROM (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) dr FROM employees) WHERE dr = N. This correctly handles ties.
What is SQL injection and how do you prevent it?
SQL injection is an attack where malicious SQL is inserted through unvalidated user input. Prevent it with parameterized queries (bind variables), stored procedures instead of dynamic SQL, and the principle of least privilege for database accounts.