InterviewStack.io LogoInterviewStack.io

SQL Fundamentals and Query Writing Questions

Comprehensive query writing skills from basic to intermediate level. Topics include SELECT and WHERE, joining tables with inner and outer joins, grouping with GROUP BY and filtering groups with HAVING, common aggregation functions such as COUNT SUM AVG MIN and MAX, ORDER BY and DISTINCT, subqueries and common table expressions, basic window functions such as ROW_NUMBER and RANK, union operations, and principles of readable and maintainable query composition. Also covers basic query execution awareness and common performance pitfalls and how to write correct, efficient queries for combining and summarizing relational data.

HardTechnical
0 practiced
Explain how to design aggregations to minimize network shuffles in distributed SQL engines. Provide an example SQL rewrite that pushes down partial aggregation before a join to reduce data transfer.
EasyTechnical
0 practiced
Write a SQL query that classifies transactions into 'high', 'medium', and 'low' buckets using a CASE expression. Use thresholds: high >= 1000, medium between 100 and 999.99, else low. Table:
transactions(id, user_id, amount, ts)
Return id, amount, bucket. Discuss readability and maintainability of CASE expressions in long queries.
HardTechnical
0 practiced
You inherit a complex SQL with multiple chained CTEs that is performing poorly. Describe a systematic approach to refactor and improve performance while preserving correctness. Mention testing strategies and how to measure impact.
MediumTechnical
0 practiced
When and why would you use temporary tables to break up a complex query into stages? Provide an example workflow where storing intermediate results in a temp table improves performance and debuggability for a multi-join aggregation job.
MediumTechnical
0 practiced
Describe the pros and cons of LIMIT/OFFSET pagination vs keyset (seek) pagination. Provide a SQL example of keyset pagination for an events table ordered by event_ts desc that returns the next page after a given last_event_ts and last_event_id.

Unlock Full Question Bank

Get access to hundreds of SQL Fundamentals and Query Writing interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.