InterviewStack.io LogoInterviewStack.io

Relational Databases and SQL Questions

Focuses on relational database fundamentals and practical SQL skills. Candidates should be able to write and reason about SELECT queries, JOINs, aggregations, grouping, filtering, common table expressions, and window functions. They should understand schema design trade offs including normalization and denormalization, indexing strategies and index types, query performance considerations and basic optimization techniques, how to read an execution plan, and transaction semantics including isolation levels and ACID guarantees. Interviewers may test writing efficient queries, designing normalized schemas for given requirements, suggesting appropriate indexes, and explaining how to diagnose and improve slow queries.

EasyTechnical
67 practiced
You are a data scientist joining an analytics team. Write a SQL query (ANSI SQL) to return the top 5 customers by total revenue in the last 12 months. Tables:
1) orders(order_id, customer_id, order_date, total_amount)2) customers(customer_id, name, signup_date)
Requirements:- Only consider orders with order_date within the last 12 months from today.- If two customers tie, order by customer_id ascending.- Return columns: customer_id, name, total_revenue.
Assume order_date is a DATE column.
MediumTechnical
81 practiced
Create a single SQL query that identifies 'churned' users: users who were active (had events) in month N-2 and N-1 but had zero events in month N. Tables: events(user_id, event_date DATE). Return user_id and last_active_month. Discuss how data delays and late-arriving events affect this metric and strategies to mitigate false churn signals.
EasyTechnical
82 practiced
Write a SQL query to pivot monthly revenue per product into columns for Jan, Feb, Mar (assume table revenue(product_id, month INT 1-12, revenue)). Use conditional aggregation so the result has columns product_id, revenue_jan, revenue_feb, revenue_mar. Explain scalability concerns for pivoting many months.
EasyTechnical
72 practiced
Explain ACID properties (Atomicity, Consistency, Isolation, Durability). For each property, give one concrete example of why it matters when building features for a recommendation system that updates user-item interactions in the OLTP database.
MediumTechnical
82 practiced
You run EXPLAIN ANALYZE on a slow query and see a sequential scan on the orders table (10M rows) despite having an index on order_date. List possible reasons the planner chose a seq scan and propose 4 actionable steps to diagnose and improve performance.

Unlock Full Question Bank

Get access to hundreds of Relational Databases and SQL interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.