SQL Query Fundamentals Questions
Core SQL for reading and shaping data: SELECT, filtering with WHERE, sorting, DISTINCT, and single-table aggregation with GROUP BY, HAVING, and aggregate functions. Covers reasoning about NULL handling, grouping semantics, and writing correct queries against a given schema. The baseline query-writing surface most data and engineering interviews open with.
Given page_views(user_id, page_id, viewed_at), compare using DISTINCT versus GROUP BY to compute the number of unique users per page. Which is more appropriate here, and why?
Describe how to write a parameterized SQL query for a report where the user can optionally filter by product_category and/or region. Show a template using placeholders, and how to make the filter a no-op when a parameter is NULL or not provided.
Explain why WHERE phone = NULL returns no rows even when some rows have a NULL phone value. Write the correct query to select rows where phone IS NULL, and a second one for rows where it IS NOT NULL.
Given orders(order_id, customer_id, amount, order_date) and vip_customers(customer_id), write a query returning orders placed by VIP customers using IN (subquery), then an equivalent using EXISTS, then an equivalent using JOIN. Discuss the performance and semantic considerations among the three for large tables.
Using ROLLUP(category, subcategory) on sales(category, subcategory, amount), write a query returning category, subcategory, total_amount, and a label distinguishing detail rows from subtotal and grand-total rows. Explain how GROUPING() or GROUPING_ID helps identify which rows are totals.
Unlock Full Question Bank
Get access to all SQL Query Fundamentals interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.