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."

PL/SQL, PostgreSQL & SQL Server

Dedicated interview question sets for PL/SQL, PostgreSQL, and SQL Server / T-SQL are in progress. In the meantime, the Oracle SQL set above covers concepts — joins, window functions, CTEs, indexing — that carry directly across every dialect.

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.