SQL for DS

SQL Interview Q&A for Data Science

Database querying and analytics SQL essentials for interview prep.

1Why SQL is critical for Data Scientists?easy
Answer: SQL is used to extract, transform, aggregate, and validate data directly from source systems.
2INNER JOIN vs LEFT JOIN?easy
Answer: INNER returns matched rows only; LEFT keeps all rows from left table plus matches.
3What is GROUP BY?easy
Answer: It groups rows by key columns so aggregate functions can be applied per group.
4HAVING vs WHERE?medium
Answer: WHERE filters before aggregation; HAVING filters aggregated groups.
5What are window functions?medium
Answer: Functions like ROW_NUMBER, RANK, SUM OVER compute values across related rows.
6What is CTE?medium
Answer: Common Table Expression is a temporary named result set that improves query readability.
7What is a primary key?easy
Answer: Unique non-null identifier for each table row.
8What is index and why used?medium
Answer: Index speeds lookups and joins by reducing full-table scans.
9What causes duplicate rows after join?medium
Answer: One-to-many or many-to-many joins with non-unique keys can multiply rows.
10How to find second highest salary?medium
Answer: Use DENSE_RANK() window function and filter rank = 2.
11What is NULL in SQL?easy
Answer: NULL represents missing/unknown value and needs IS NULL checks.
12UNION vs UNION ALL?easy
Answer: UNION removes duplicates; UNION ALL keeps all rows and is faster.
13What is query execution plan?hard
Answer: It shows how database executes a query and helps identify performance bottlenecks.
14What is normalization?medium
Answer: Structuring tables to reduce redundancy and improve data integrity.
15One-line SQL summary for DS interviews?easy
Answer: SQL is the most practical skill for turning raw database data into analysis-ready inputs.