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
53 practiced
Write an SQL query to find customers who placed more than 5 completed orders in the last 30 days. Table: orders(order_id, customer_id, order_date DATE, status). Return customer_id and order_count. Use GROUP BY and HAVING; explain why HAVING is required in this case.
EasyTechnical
45 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.
EasyTechnical
56 practiced
As a BI analyst building an executive dashboard, write an ANSI SQL query that returns the 50 largest completed orders between '2024-01-01' and '2024-06-30', sorted by amount descending. Table schema: orders(order_id INT, customer_id INT, order_date DATE, amount DECIMAL(10,2), status VARCHAR). Return columns: order_id, customer_id, order_date, amount. Do not use SELECT * and make the query parameterizable for date window and status.
EasyTechnical
49 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.
MediumTechnical
54 practiced
You must implement a multi-step transformation for a BI dataset involving heavy aggregation and joins. Compare using CTEs (inline) versus temporary tables (materialized) in terms of performance, readability, and ability to add indexes on intermediate results. Provide guidance when to prefer each approach.

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.