TGViewer
Data Analytics Data Analytics @sqlspecialist · 111K subscribers
Post #2848 4.64K
SELECT EmployeeName,
ROW_NUMBER() OVER (ORDER BY Salary DESC) AS RankNo
FROM Employees;


21. Explain RANK() and DENSE_RANK()

RANK(): Ranks with gaps. Example: 1, 2, 2, 4

DENSE_RANK(): Ranks without gaps. Example: 1, 2, 2, 3

22. What are Indexes?

Indexes improve query speed.

Benefits:

✔ Faster searches,

✔ Faster filtering

Drawback:

❌ Extra storage

23. What Causes Slow SQL Queries?

Common reasons:

✔ Missing indexes

✔ Too many joins

✔ Large datasets

✔ SELECT _ usage

✔ Unoptimized subqueries

24. How Do You Optimize SQL Queries?

Best practices:

✔ Create indexes

✔ Avoid SELECT _

✔ Filter early

✔ Optimize joins

✔ Use execution plans

25. What are Views?

Virtual tables based on SQL queries.

CREATE VIEW EmployeeView AS
SELECT EmployeeID, EmployeeName
FROM Employees;


26. What are Stored Procedures?

Reusable SQL programs stored in database.

Benefits:

✔ Faster execution,

✔ Reusable code,

✔ Better security

27. What are Transactions?

A group of SQL operations treated as one unit.

Example: Bank transfer transaction.

Commands: BEGIN TRANSACTION; COMMIT; ROLLBACK;

28. Explain ACID Properties

Atomicity: All or nothing.

Consistency: Data remains valid.

Isolation: Transactions don't interfere.

Durability: Committed changes stay permanent.

29. Find Duplicate Records

SELECT Email, COUNT(*)
FROM Customers
GROUP BY Email
HAVING COUNT(*) > 1;


30. Find Second Highest Salary

SELECT MAX(Salary)
FROM Employees
WHERE Salary <
(
SELECT MAX(Salary)
FROM Employees
);


31. Calculate Running Totals

SELECT OrderDate, Sales,
SUM(Sales) OVER (ORDER BY OrderDate) AS RunningTotal
FROM Orders;


32. Find Top Selling Products

SELECT ProductName, SUM(Sales) AS TotalSales
FROM Orders
GROUP BY ProductName
ORDER BY TotalSales DESC;


33. Calculate Month-over-Month Growth

SELECT Month, Sales,
LAG(Sales) OVER(ORDER BY Month) AS PreviousMonth
FROM SalesData;


34. Difference Between UNION and UNION ALL?

UNION: Removes duplicates.

UNION ALL: Keeps duplicates. UNION ALL is faster.

35. What are NULL Values?

NULL means missing or unknown value.

SELECT * FROM Employees WHERE ManagerID IS NULL;


36. Difference Between CHAR and VARCHAR?

CHAR: Fixed length.

VARCHAR: Variable length.

VARCHAR saves storage.

37. What is a Primary Key?

A unique identifier for each record.

Properties:

✔ Unique,

✔ Not NULL

38. What is a Foreign Key?

Maintains relationships between tables. Ensures referential integrity.

39. Difference Between Clustered and Non-Clustered Indexes?

Clustered Index: Stores actual table data. Only one per table.

Non-Clustered Index: Separate structure pointing to data. Multiple allowed.

40. Explain Query Execution Plans

Execution plans show how SQL Server executes a query.

Used to identify:

✔ Full table scans,

✔ Expensive joins,

✔ Missing indexes,

✔ Performance bottlenecks

💡 Most Data Analyst SQL interviews focus heavily on:

• Joins

• Group By

• Window Functions

• CTEs

• Subqueries

• Ranking Functions

• Real-world SQL scenarios

Double Tap ❤️ For Part-2 🚀
  • ❤ 25
More from @sqlspecialist
  1. Oct 8, 2026🎓 𝗠𝗶𝗰𝗿𝗼𝘀𝗼𝗳𝘁 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝘄𝗶𝘁𝗵 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗲𝘀! 🚀🔥 Upgr…
  2. Oct 7, 2026📊 Kandinsky 6.0 Video: AI-Powered Content Creation for Analysts The new Kandinsky 6.0 Vid…
  3. Oct 7, 2026Alternatively, depending on the Excel version and requirement, I could use functions such…
  4. Oct 7, 2026📊 Data Analyst Interview Series — Part 5 Guys, let's continue our Data Analyst Interview…
  5. Oct 7, 2026🚀𝗣𝗮𝘆 𝗔𝗳𝘁𝗲𝗿 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 | 𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰…
  6. Oct 7, 2026🔟 What is the difference between UNION and JOIN? Sample Answer: "JOIN combines columns fr…
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 →