TGViewer
Data Analytics Data Analytics @sqlspecialist · 111K subscribers
Post #2558 8.54K
Data Analyst Interview Questions with Answers: Part-3

21. What is SELECT used for?
SELECT is used to fetch specific columns or data from a table.
Example:
SELECT customer_name, sales FROM orders;

This query returns customer names and their sales from the orders table.

 

22. Difference between WHERE and HAVING?
WHERE filters rows before aggregation.
HAVING filters results after aggregation.
Example:
SELECT product, SUM(sales) AS total_sales
FROM orders
WHERE region = 'East'
GROUP BY product
HAVING SUM(sales) > 100000;

Here, WHERE filters region first, HAVING filters aggregated sales.

 

23. What is GROUP BY?
GROUP BY groups rows with the same values so aggregate functions can be applied.
Example:
SELECT region, SUM(sales) AS total_sales
FROM orders
GROUP BY region;

This gives total sales per region.

 

24. What are aggregate functions?
Aggregate functions perform calculations on multiple rows.
Common examples:
• COUNT → total rows
• SUM → total value
• AVG → average
• MIN / MAX → smallest or largest value
Example:
SELECT COUNT(order_id), AVG(sales)
FROM orders;

 

25. Difference between INNER JOIN and LEFT JOIN?
INNER JOIN: Returns only matching records.
LEFT JOIN: Returns all rows from left table and matching rows from right table.
Example:
SELECT o.order_id, c.customer_name
FROM orders o
LEFT JOIN customers c
ON o.customer_id = c.customer_id;

All orders appear even if customer info is missing.

 

26. What are subqueries?
A subquery is a query inside another query.
Example:
SELECT *
FROM orders
WHERE sales > (SELECT AVG(sales) FROM orders);

Returns orders with sales above average.

 

27. What is a CTE?
CTE (Common Table Expression) is a temporary named result set that improves readability.
Example:
WITH sales_summary AS (
SELECT region, SUM(sales) AS total_sales
FROM orders
GROUP BY region
)
SELECT *
FROM sales_summary
WHERE total_sales > 500000;

 

28. How do you handle duplicates in SQL?
Identify duplicates:
SELECT customer_id, COUNT(*)
FROM orders
GROUP BY customer_id
HAVING COUNT(*) > 1;

Remove duplicates (using ROW_NUMBER):
DELETE FROM orders
WHERE order_id IN (
SELECT order_id
FROM (
SELECT order_id, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date) rn
FROM orders
) t
WHERE rn > 1
);

 

29. How do you handle NULL values?
Check NULL:
SELECT *
FROM orders
WHERE sales IS NULL;

Replace NULL:
SELECT COALESCE(sales, 0) AS sales_amount
FROM orders;

 

30. What are window functions?
Window functions perform calculations across rows without grouping them.
Example:
SELECT customer_id, sales, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY sales DESC) AS rn
FROM orders;

This ranks sales per customer without collapsing rows.

Double Tap ♥️ For Part-4
  • ❤ 44
  • 👍 2
More from @sqlspecialist
  1. Oct 12, 2026🚀 𝗪𝗵𝗶𝗰𝗵 𝗧𝗲𝗰𝗵 𝗦𝗸𝗶𝗹𝗹 𝗪𝗶𝗹𝗹 𝗬𝗼𝘂 𝗠𝗮𝘀𝘁𝗲𝗿 𝗶𝗻 𝟮𝟬𝟮𝟲? Want to buil…
  2. Oct 9, 2026“Here, the data is sorted by the second column in descending order and the first five rows…
  3. Oct 9, 2026📊 Data Analyst Interview Series — Part 6 Guys, let's continue our Data Analyst Interview…
  4. Oct 9, 2026🇮🇳 𝗚𝗢𝗩𝗘𝗥𝗡𝗠𝗘𝗡𝗧 𝗢𝗙 𝗜𝗡𝗗𝗜𝗔 — 𝗔𝗜𝗖𝗧𝗘 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝟮𝟬𝟮𝟲 🚀…
  5. Oct 8, 2026🎓 𝗠𝗶𝗰𝗿𝗼𝘀𝗼𝗳𝘁 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝘄𝗶𝘁𝗵 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗲𝘀! 🚀🔥 Upgr…
  6. Oct 7, 2026📊 Kandinsky 6.0 Video: AI-Powered Content Creation for Analysts The new Kandinsky 6.0 Vid…
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 →