Post content
☑️Top 15 SQL Interview Questions for Data Analysts💻 1️⃣What is the difference between WHERE and HAVING clauses? ⦁ WHERE filters rows before grouping (on raw data). ⦁ HAVING filters groups after aggregation. ⦁ WHERE cannot use aggregates; HAVING can. 2️⃣Explain the concept of joins. What are different types of joins in SQL? Joins combine rows from two or more tables based on related columns. Types include: ⦁ INNER JOIN (only matching rows) ⦁ LEFT JOIN (all from left + matched right) ⦁ RIGHT JOIN (all from right + matched left) ⦁ FULL OUTER JOIN (all from both) 3️⃣How do you find duplicate records in a table? Use GROUP BY on columns and HAVING COUNT(*) > 1 to find duplicates. Example: SELECT column, COUNT(*) FROM table GROUP BY column HAVING COUNT(*) > 1; 4️⃣What is a subquery? When would you use one? A query nested inside another query, used for filtering, aggregation, or conditional logic when a single query isn’t sufficient. 5️⃣What is the difference between RANK(), DENSE_RANK(), and ROW_NUMBER()? ⦁ ROW_NUMBER() assigns unique sequential numbers per partition. ⦁ RANK() gives the same rank to ties, skipping subsequent ranks. ⦁ DENSE_RANK() gives the same rank to ties without gaps. 6️⃣How do you handle NULL values in SQL? Use IS NULL / IS NOT NULL to check nulls, COALESCE() to replace NULLs with defaults. 7️⃣Explain the difference between INNER JOIN and LEFT JOIN. ⦁ INNER JOIN returns only matching rows. ⦁ LEFT JOIN returns all left table rows plus matching right rows (NULL if no match). 8️⃣What are window functions? Provide examples. Functions that operate over a set of rows related to the current row without collapsing results. Examples: ROW_NUMBER(), RANK(), SUM() OVER() 9️⃣How would you write a query to get the second highest salary from a table? Example: SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees); 🔟What is the difference between UNION and UNION ALL? ⦁ UNION removes duplicates. ⦁ UNION ALL includes all duplicates. 1️⃣1️⃣How do indexes improve performance? Indexes speed up data retrieval by allowing quick lookup without scanning the full table, like an index in a book. 1️⃣2️⃣Explain normalization and its types. Normalization organizes data to reduce redundancy and improve integrity. Forms: 1NF, 2NF, 3NF, BCNF, etc. 1️⃣3️⃣What’s the difference between DELETE, TRUNCATE, and DROP? ⦁ DELETE removes rows one by one (can have WHERE), logs changes. ⦁ TRUNCATE removes all rows quickly, minimal logging. ⦁ DROP deletes table structure and data. 1️⃣4️⃣How would you optimize a slow SQL query? Analyze execution plan, add indexes, avoid unnecessary columns, use joins/subqueries efficiently, limit data scanned. 1️⃣5️⃣Walk me through how you'd write a SQL query from scratch based on a business question. Understand requirements → identify tables/columns → decide filters/joins → select needed columns → test and optimize query. 📌Pro Tip: Practice writing queries with real datasets to improve speed and clarity during interviews. 💬Tap ❤️ if this was useful!