TGViewer
Data Analytics Data Analytics @sqlspecialist · 111K subscribers
Post #2273 6.65K
☑️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!
  • ❤ 21
  • 👍 2
  • 🥰 1
  • 👏 1
More from @sqlspecialist
  1. Oct 16, 2026𝗗𝗮𝘁𝗮 𝘀𝗰𝗶𝗲𝗻𝗰𝗲 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗪𝗶𝘁𝗵 𝗔𝗜😍 Future Ready Data Scien…
  2. Oct 14, 2026I could then categorize customers into groups such as Active, At Risk, and Inactive and su…
  3. Oct 14, 2026📊 Data Analyst Interview Series — Part 10 Guys, let's continue our Data Analyst Interview…
  4. Oct 13, 2026📊 Data Analyst Interview Series — Part 9 Guys, let's continue our Data Analyst Interview…
  5. Oct 13, 2026𝗧𝗢𝗣 𝗙𝗥𝗘𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦 𝗧𝗢 𝗕𝗢𝗢𝗦𝗧 𝗬𝗢𝗨𝗥 𝗦𝗞𝗜𝗟𝗟𝗦 𝗜𝗡 𝟮𝟬𝟮𝟲! Explor…
  6. Oct 12, 20268️⃣ You receive a dataset with inconsistent date formats. How would you clean it? Sample A…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →