FOCUSED INTERVIEW PRACTICE · DOWNLOADABLE PDF

SQL · 4-7 years interview questions & answers

Practise SQL queries, multi-table joins and interview scenarios. Check your approach against a numbered answer sheet with SQL solutions and short explanations.

220 questions73 PDF pages4-7 years experience
₹259One-time payment · one PDF
Buy this PDF · ₹259Preview before you buy ↓

Model answers included · No account required · Private download after successful payment

SEE WHAT YOU WILL PRACTISE

Sample questions from this PDF

Try the questions first. Open the model answer below to see the explanation and SQL solution.

Sample 1

Using Customers, Orders, OrderLines and Payments, return each customer's line total and payment total without multiplying either child table. Include customers with no orders as 0.

Read the model answer from this PDF

Aggregate each child to order grain before the customer aggregation.

Example schema: Customers(customer_id), Orders(order_id, customer_id), OrderLines(order_id, quantity, unit_price), Payments(order_id, amount). Customer and order IDs are unique.

WITH l AS (
  SELECT order_id, SUM(quantity * unit_price) AS total
  FROM OrderLines GROUP BY order_id
), p AS (
  SELECT order_id, SUM(amount) AS total
  FROM Payments GROUP BY order_id
)
SELECT c.customer_id,
       COALESCE(SUM(l.total), 0) AS line_total,
       COALESCE(SUM(p.total), 0) AS paid_total
FROM Customers c
LEFT JOIN Orders o ON o.customer_id = c.customer_id
LEFT JOIN l ON l.order_id = o.order_id
LEFT JOIN p ON p.order_id = o.order_id
GROUP BY c.customer_id;

SQL formatting is expanded for readability. Check syntax for your database.

Sample 2

Use a recursive CTE to produce October 2026 dates, then LEFT JOIN Orders and Customers. Return order count per date, counting only orders with a customer match and keeping zero-order days.

Sample 3

Using Customers, Orders, OrderLines and Products, find customers who bought at least two distinct Office-category products on Paid orders. Office means category_id 10.

Your revision, organised

  • 220 numbered questions across 20 topics
  • Numbered answer sheet for checking your reasoning
  • Clickable topic index for focused revision
  • 73 PDF pages to save and study at your pace
See all topics in this PDF
  • Joins, row counts and reporting level · 11 questions
  • Anti joins and existence filters · 11 questions
  • Conditional aggregation and ratios · 11 questions
  • Window frames and running totals · 11 questions
  • LAG, LEAD and change detection · 11 questions
  • Top N, ties and deduplication · 11 questions
  • Gaps, islands and consecutive groups · 11 questions
  • Recursive CTEs and hierarchies · 11 questions
  • CTEs, temp tables and views · 11 questions
  • Dates, time zones and calendars · 11 questions
  • NULL and missing values · 11 questions
  • Set operations and reconciliation · 11 questions
  • Indexes and efficient WHERE filters · 11 questions
  • Execution plans and estimates · 11 questions
  • Transactions and isolation · 11 questions
  • Locks and deadlocks · 11 questions
  • Upserts and incremental loads · 11 questions
  • Data modelling and constraints · 11 questions
  • Query parameters and stored routines · 11 questions
  • Business analytics exercises · 11 questions

A curated practice bank of independently written exercises and adapted public interview themes. These are not verified questions from particular companies. Experience bands indicate practice depth.

Try free SQL interview questions

Practise the fundamentals, explain a scenario and compare your approach with a short answer.

Read the SQL interview practice guide