TGViewer
Data Analytics Data Analytics @sqlspecialist · 111K subscribers
Post #2463 9.23K
✅ Top SQL Interview Questions with Answers: Part-3 🧠

21. How do you handle NULLs in queries?
Use IS NULL, IS NOT NULL, COALESCE(), or IFNULL() to manage NULLs.
Example:
SELECT name FROM users WHERE email IS NULL;


22. What is COALESCE() in SQL?
It returns the first non-NULL value from a list.
SELECT COALESCE(phone, 'Not Provided') FROM customers;


23. What are aggregate functions? 📊
Functions that perform calculations on multiple rows:
- COUNT()
- SUM()
- AVG()
- MAX()
- MIN()

24. What is GROUP BY and how does it work?
It groups rows that have the same values and is used with aggregate functions.
SELECT department, COUNT(*) FROM employees GROUP BY department;


25. What is the difference between COUNT(\*) and COUNT(column)?
- COUNT(\*): Counts all rows, including those with NULLs.
- COUNT(column): Counts non-NULL values in that column.

26. What are window functions? 🪟
They perform calculations across rows related to the current row without collapsing results.
Examples: ROW_NUMBER(), RANK(), SUM() OVER()

27. Difference between RANK(), DENSE_RANK(), and ROW_NUMBER()
- RANK(): Skips ranks on ties (1, 1, 3)
- DENSE_RANK(): No gaps in ranking (1, 1, 2)
- ROW_NUMBER(): Unique sequence for each row (1, 2, 3)

28. What is the use of LAG() and LEAD()?
They access previous (LAG) or next (LEAD) row values in the result set.
SELECT name, salary, LAG(salary) OVER (ORDER BY id) AS prev_salary FROM employees;


29. What is a CASE statement?
It's used for conditional logic in queries.
SELECT name,
CASE
WHEN salary > 5000 THEN 'High'
ELSE 'Low'
END AS salary_level
FROM employees;


30. What is the difference between CHAR and VARCHAR?
- CHAR(n): Fixed-length, always reserves n characters. (Padding with spaces if shorter)
- VARCHAR(n): Variable-length, uses space based on actual content. (More efficient for varying lengths)

💬 Double Tap ❤️ For Part-4
  • ❤ 29
More from @sqlspecialist
  1. Oct 12, 20268️⃣ You receive a dataset with inconsistent date formats. How would you clean it? Sample A…
  2. Oct 12, 2026📊 Data Analyst Interview Series — Part 7 Guys, let's continue our Data Analyst Interview…
  3. Oct 12, 2026🚀 𝗪𝗵𝗶𝗰𝗵 𝗧𝗲𝗰𝗵 𝗦𝗸𝗶𝗹𝗹 𝗪𝗶𝗹𝗹 𝗬𝗼𝘂 𝗠𝗮𝘀𝘁𝗲𝗿 𝗶𝗻 𝟮𝟬𝟮𝟲? Want to buil…
  4. Oct 9, 2026“Here, the data is sorted by the second column in descending order and the first five rows…
  5. Oct 9, 2026📊 Data Analyst Interview Series — Part 6 Guys, let's continue our Data Analyst Interview…
  6. Oct 9, 2026🇮🇳 𝗚𝗢𝗩𝗘𝗥𝗡𝗠𝗘𝗡𝗧 𝗢𝗙 𝗜𝗡𝗗𝗜𝗔 — 𝗔𝗜𝗖𝗧𝗘 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝟮𝟬𝟮𝟲 🚀…
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 →