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.

MediumTechnical
40 practiced

SELECT category, product_name FROM sales GROUP BY category; raises an error about a non-aggregated column. Explain why, and give two different corrections depending on business intent: picking one representative product per category, versus listing every category/product pair.

EasyTechnical
47 practiced

How do AND, OR, and NOT combine in a SQL WHERE clause, and how do parentheses change the result? Using products(product_id, category, price, on_sale), show how WHERE category = 'shirts' AND price < 20 OR on_sale = true differs from the same predicate with explicit parentheses, and explain why.

EasyTechnical
40 practiced

Given users(id INT PRIMARY KEY, name VARCHAR, email VARCHAR, status VARCHAR, created_at TIMESTAMP), write a query that returns id, name, and email for users whose status is 'active', ordered by created_at descending, limited to the first 100 rows.

EasyTechnical
39 practiced

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.

EasyTechnical
73 practiced

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.

Unlock Full Question Bank

Get access to all 27 SQL Query Fundamentals interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.