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.

EasyTechnical
0 practiced
In customers(customer_id, name, phone), many phone entries are NULL or empty. As a BI analyst creating contact lists, write SQL that returns customer_id, name and a contact_phone column that shows phone when present, otherwise 'N/A'. Also explain how to treat whitespace-only values.
EasyTechnical
0 practiced
Write two SQL patterns to find customers who have never placed an order. Tables: customers(customer_id, name) and orders(order_id, customer_id). Provide both a LEFT JOIN ... IS NULL and a NOT EXISTS variant; explain the null semantics and which is safer in presence of NULLs in orders.customer_id.
HardTechnical
0 practiced
Design an efficient SQL deduplication query for events(user_id, event_ts, source_priority INT, event_id) where the rule is: keep one row per (user_id, event_id) group with highest source_priority, then most recent event_ts as tie-breaker. Provide a performant SQL using window functions and explain indexing and partitioning recommendations for a table of hundreds of millions of rows.
HardTechnical
0 practiced
Write sample SQL checks to detect data-quality issues: 1) a daily revenue spike defined as today's revenue > 3x the 7-day moving average; 2) orphaned order_items with no matching order; 3) duplicate order_ids in orders table. Provide queries and explain how you'd integrate these into automated alerts.
EasyTechnical
0 practiced
Write an SQL query to list customers ordered by last_login descending and then by name ascending, ensuring NULL last_login values appear last. Table: customers(customer_id, name, last_login TIMESTAMP). Address SQL dialect differences where NULLS LAST may not be supported.

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.