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.
Describe the practical differences between DELETE, TRUNCATE, and DROP. Cover transactional behavior and rollback, performance, permission requirements, and whether triggers fire for each.
Given users(user_id, name, email) and orders(order_id, user_id, total_amount, order_date), write a query listing name, email, order_id, and total_amount for orders over $100, including only users who have at least one such order.
Given events(event_id, user_id, event_type, occurred_at), write a query computing Daily Active Users (DAU) for the last 30 full days: count of distinct users per UTC day, treating multiple same-day events per user as one. Compare writing this with COUNT(DISTINCT ...) versus GROUP BY, and note performance considerations at scale.
Given orders(order_id, vendor_id, amount, status) and vendors(vendor_id, name), compute average order value per vendor, but only for completed orders and only for vendors with at least 100 such orders. Write the query, applying the status filter with WHERE (before aggregation) and the count threshold with HAVING (after aggregation), and explain why each belongs where it does.
Write a PostgreSQL statement to insert into users(id, email, name, updated_at) or update the existing row on conflict of id (an upsert), updating name and setting updated_at = now(). Briefly describe the SQL Server MERGE alternative, and why upserts are useful for idempotent data loads.
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.