Menu
CoddyTech

SQL Interview Questions and Answers

SQL interview questions from keys and joins to GROUP BY, subqueries, window functions, the classic queries, indexes and transactions. Each topic has its own page of questions, with short answers and code you can run.

98 questions in 8 topics

SQL Basics Interview Questions

Keys, constraints, NULL, filtering and the basic commands, with several predict-the-output questions.

All 20 questions

SQL Joins Interview Questions

Join types, the row counts they produce, and the traps behind wrong totals.

All 10 questions

SQL GROUP BY and Aggregate Function Interview Questions

Aggregates, GROUP BY and HAVING, conditional counts, string aggregation and subtotals.

All 10 questions

SQL Subqueries and CTEs Interview Questions

Correlated subqueries, IN vs EXISTS, the NOT IN null trap, CTEs, recursion and UNION.

All 10 questions

SQL Window Functions Interview Questions

ROW_NUMBER, RANK, DENSE_RANK, running totals, LAG and LEAD, and the frame rules that catch experienced developers.

All 10 questions

SQL Query Interview Questions

The classic queries asked in a shared editor; each one runs, so change the data and try your own.

All 13 questions

Advanced SQL Interview Questions

Indexes, query plans, transactions, isolation, locking and schema design.

All 15 questions

SQL Interview Questions for Data Analysts

Reporting queries: dates, percentages, pivots, medians, retention and streaks.

All 10 questions

Frequently Asked Questions

How do I prepare for a SQL interview?

Write queries, do not only read answers. Practice joins, GROUP BY with HAVING, subqueries and window functions until you need no reference, then the classic questions (second highest salary, duplicates, top N per group) on a small table of your own. In the interview, state your assumptions about ties, NULLs and empty groups.

What SQL questions are asked to freshers and to experienced candidates?

Freshers get definitions and short queries: keys, constraints, DELETE vs TRUNCATE, WHERE vs HAVING, joins, second highest salary. At 3 to 5 years expect window functions, CTEs, harder queries and indexes. At 5 to 10 years: query plans, isolation levels, deadlocks, schema design and fixing a slow production query.

Which database should I practice on for SQL interviews?

Any of them; most interviews accept standard SQL. If the job names a database, practice on it (MySQL and PostgreSQL are most common, SQL Server in many enterprise roles), and know the differences that come up: LIMIT vs TOP, date functions, string aggregation and upserts.

Which SQL topics matter most for a data analyst interview?

Joins, GROUP BY with conditional aggregation (SUM(CASE WHEN ...)), window functions (ranking, running totals, LAG), dates, and turning a business question into a query: retention, conversion, month-over-month growth. Indexes and transactions matter far less than for a developer role.

How long does it take to prepare SQL for interviews?

If you already know basic SELECT, two to three weeks of daily practice covers this page; from zero, plan four to six weeks. Window functions and the classic queries take longest, so start them once joins feel easy.

Do I need DSA for a SQL or data analyst role?

Less than for a software engineering role, but many companies add an easy coding round: arrays, strings, hash maps. Duplicates, the Kth largest value and running sums are the same problems in SQL and in code, so the practice problems below are a good warm-up.

Coddy programming languages illustration

Learn to code with Coddy

Get started