7 min read

SQL Interview Questions and Answers: Beginner to Advanced, With Sample Queries

joseph cole

Updated on April 1, 2024

SQL Interview Questions and Answers: Beginner to Advanced, With Sample Queries

joseph cole

Updated on April 1, 2024

In this post

CREATE YOUR ACCOUNT

Accelerate the hiring of top talent

Make talent quality your leading analytic with skills-based hiring solution.

Get started

Plenty of candidates can define a JOIN. Fewer can write one against a messy table and explain why their result has duplicate rows. Good SQL interview questions find that gap early, before an analyst or developer ends up on a team that needed someone who can actually query production data.

This guide groups SQL interview questions by difficulty, gives a sample query or model answer for the questions that matter most, and notes what a strong answer shows. Use it to build an interview loop, calibrate a hiring manager, or check your own understanding if you’re preparing.

Jump to a section:

Why SQL interview questions still matter

Resumes list SQL the way they list Excel: almost everyone claims it, and the claim covers anything from a few SELECT statements to tuning queries on billion row tables. Targeted questions do three jobs. They show whether stated experience matches real skill, they show how a candidate reasons when a query doesn’t return what they expected, and they give every candidate the same questions, which keeps the evaluation consistent.

Beginner SQL interview questions

Best for: business analysts, data analysts early in their careers, QA testers, and support engineers who query data occasionally.

These questions cover the vocabulary and basic commands. A candidate who struggles here will struggle with everything after it.

Core concepts to cover:

  • What is SQL, and how does it differ from a SQL dialect such as MySQL, PostgreSQL or Transact SQL?
  • What is a database, a DBMS and an RDBMS?
  • What are tables, fields, schemas, entities and relationships?
  • What is the difference between NULL, zero and a blank value?
  • What are constraints, keys, indexes, aliases and comments used for?
  • What are the main categories of SQL commands (DDL, DML, DCL, TCL)?

Example: NULL vs zero

Question: Why does WHERE discount = NULL return no rows, even when some discounts are missing?

What a strong answer shows: NULL means “unknown,” so any comparison with = evaluates to unknown, not true. The correct filter is WHERE discount IS NULL. Strong candidates also mention that aggregate functions like AVG() ignore NULLs, which changes results.

Example: counting and selecting

Question: How would you count customers per country and show only countries with more than 100 customers?

SELECT country, COUNT(*) AS customer_count
FROM customers
GROUP BY country
HAVING COUNT(*) > 100;

What a strong answer shows: they use HAVING for the aggregate filter, not WHERE, and can explain why.

Other beginner questions: How do you create, update and delete a table? How do you select specific columns? What does DISTINCT do? What is a subquery? What are the main uses of SQL in a business?

Intermediate SQL interview questions

Best for: SQL developers, ETL developers, BI developers and analysts who own reporting.

At this level, the questions test whether a candidate can combine functions, understand execution order and design tables that stay clean as data grows.

Topics to cover:

  • Aggregate vs scalar functions; character manipulation functions; the CASE expression
  • ORDER BY, set operators (UNION, UNION ALL, INTERSECT, EXCEPT) and pattern matching with LIKE
  • The logical order in which clauses execute
  • Nested vs correlated subqueries
  • TRUNCATE vs DELETE vs DROP
  • WHERE vs HAVING
  • Normalization and denormalization; clustered vs non clustered indexes
  • Primary key vs unique key; composite keys; relationship types
  • Views, views built on other views, and what happens when an underlying table is dropped

Example: JOIN types

Question: You join orders to customers with an INNER JOIN and the order count drops. Why, and how would you keep every order?

What a strong answer shows: an INNER JOIN keeps only rows that match on both sides, so orders with a missing or invalid customer_id disappear. A LEFT JOIN from orders keeps them, with NULLs in the customer columns. Strong candidates suggest checking for those orphaned rows as a data quality signal.

Example: removing duplicates

Question: How do you find duplicate email addresses in a users table?

SELECT email, COUNT(*) AS occurrences
FROM users
GROUP BY email
HAVING COUNT(*) > 1;

Follow up: How would you delete the duplicates but keep the earliest record? Listen for a window function or a self join on the key, and for the candidate asking which record counts as “earliest” before writing anything.

Example: execution order

Question: Why can’t you use a column alias defined in SELECT inside the WHERE clause?

What a strong answer shows: WHERE is evaluated before SELECT, so the alias doesn’t exist yet. The logical order is FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY.

Other intermediate questions: How do you select odd or even rows? How do you insert rows in bulk? How do you find the last inserted ID? How do you return random rows? How do you search text by pattern?

Advanced SQL interview questions

Best for: senior data engineers, data architects, database administrators and data scientists who own pipelines.

Advanced questions move from writing correct queries to writing queries that stay correct and fast at scale, under concurrent load.

Topics to cover:

  • ACID vs BASE; sharding; when a NoSQL store fits better than a relational database; normalization tradeoffs
  • How indexing affects reads and writes; reading an execution plan; using EXPLAIN; tuning a slow query
  • Materialized views vs regular views; common table expressions (CTEs); stored procedures vs functions; ROLLUP and CUBE
  • Transactions, isolation levels and locking
  • Partitioning, replication and handling large datasets

Example: window functions

Question: Return the top three products by revenue in each category.

WITH ranked AS (
  SELECT category, product_id, revenue,
         DENSE_RANK() OVER (PARTITION BY category ORDER BY revenue DESC) AS rnk
  FROM product_revenue
)
SELECT category, product_id, revenue
FROM ranked
WHERE rnk <= 3;

What a strong answer shows: they choose between ROW_NUMBER, RANK and DENSE_RANK on purpose and can explain what happens with ties.

Example: slow query diagnosis

Question: A dashboard query that ran in two seconds now takes two minutes. Walk me through what you’d check.

What a strong answer shows: a sequence, not a guess. Check the execution plan for full scans, confirm the filtered columns are indexed, look for a function wrapped around an indexed column, check whether table statistics are stale, and ask what changed in data volume. Red flag: jumping straight to “add more indexes” without looking at the plan.

Example: isolation levels

Question: What problem does the REPEATABLE READ isolation level solve, and what can still go wrong?

What a strong answer shows: it prevents non repeatable reads within a transaction. Depending on the engine, phantom reads may still occur, and higher isolation means more locking or more serialization failures.

Scenario questions: write the query

Definitions tell you what a candidate has read. A short query task tells you what they can do. Good scenario prompts for a 20 to 30 minute slot:

  • Find the second highest salary in each department, handling ties.
  • Calculate month over month revenue change from an orders table.
  • Find customers who placed an order in January but not in February.
  • Identify users whose first and most recent login are more than 90 days apart.

Ask the candidate to talk through assumptions before they start. The best ones ask about NULLs, ties and time zones without being prompted.

How to verify SQL skills beyond the interview

Verbal SQL interview questions have a ceiling. Candidates can rehearse definitions, and question lists like this one are public. The stronger signal comes from watching someone write and debug a query against real tables.

Glider’s Technical Assessments cover 250+ languages and technologies, including MySQL, PostgreSQL, Oracle, MSSQL and PL/SQL, so a SQL screen can run on the dialect your team actually uses. Coding Simulations recreate a working environment where candidates build and debug rather than answer isolated questions, and Live Coding Interviews let an interviewer watch a candidate work through a scenario like the ones above.

Because remote SQL tests are easy to outsource, pair them with AI Proctoring and ID Verify, so the person who passes the test is the person you interview and hire. Proctoring flags are evidence for a recruiter to review, not automatic rejections. If you’re also screening for reporting or analysis roles, the Skills Test Library and the Interview Questions Library have related tests and question sets.

FAQ

What are the most common SQL interview questions?

The most common SQL interview questions cover JOIN types, the difference between WHERE and HAVING, GROUP BY with aggregates, primary vs unique keys, normalization, indexes, and finding the second highest value in a column. Advanced rounds add window functions, CTEs, execution plans and isolation levels.

What SQL questions should I ask a data analyst?

Focus on aggregation, joins, filtering, date handling and window functions, then give one short scenario such as month over month revenue change. Data analysts rarely need deep database administration knowledge, so weight query writing and result interpretation over tuning and replication.

How do I evaluate a candidate’s SQL answer?

Look for correct logic first, then how the candidate handles edge cases (NULLs, ties, duplicates), then readability. A candidate who states assumptions and checks their result is usually stronger than one who writes a fast query and stops.

How long should a SQL technical interview take?

A typical SQL round runs 30 to 60 minutes: a few concept questions to calibrate, then one or two query tasks. A hands on assessment before the interview can shorten the live round, since basic query skill is already verified.

What is the difference between beginner and advanced SQL questions?

Beginner questions test vocabulary and basic commands such as SELECT, WHERE and GROUP BY. Advanced questions test performance, concurrency and design: execution plans, indexing tradeoffs, isolation levels, partitioning and replication.

Are SQL interview questions enough to assess SQL skills?

Not on their own. Questions show understanding, but a timed, proctored query task shows ability. Most teams get the clearest signal by combining a short SQL assessment with a focused interview.

Can candidates practice with these SQL interview questions?

Yes. The questions and sample queries here are standard SQL concepts. Practicing them helps, but interviewers usually adapt questions to their own schema, so understanding why a query works matters more than memorizing it.

Asking good SQL interview questions is the first step. Watching a candidate write the query is the second, and it’s the one that tells you whether they’ll be useful in the first month. Book a demo to see how Glider runs SQL assessments with proctoring built in.

Candidate Identity Checks Are No Longer Optional: A Candidate Identity Verification Recruiting Guide

A recruiter screens a strong candidate on video, a hiring manager runs a solid technical round, and an offer goes out. On day one, the person who logs in is not the person who interviewed. Nobody on the team did anything careless. The process simply never confirmed who the candidate was. That gap is why […]

Exploring Challenges Faced By Recruiters in Technical Hiring

Introduction  Technical roles are some of the hardest to fill. The process is a landmine of recruitment challenges.  HR teams often find themselves under-resourced and struggling to find suitable talent, while engineers waste too much time interviewing candidates who don’t meet the necessary qualifications.  Meanwhile, high-quality candidates get frustrated by slow and inefficient hiring processes and […]

QA & Testing​ – Top Job Roles and Skills

What is QA and Testing? Quality Assurance (QA) and testing are integral processes in software development aimed at ensuring the reliability, functionality, and usability of applications. QA involves establishing standards and procedures to monitor and improve the software development lifecycle, focusing on preventing defects and identifying areas for optimization. It encompasses various activities such as […]

chevron-down