TGViewer
Data Analyst Interview Resources Data Analyst Interview Resources @dataanalystinterview · 52.5K subscribers
Post #1555 724
35 Important SQL Interview Questions with Detailed Answers:

1. Explain order of execution of SQL.

Order: FROM → JOIN → ON → WHERE → GROUP BY → HAVING → SELECT → DISTINCT → ORDER BY → LIMIT. SQL queries are processed in this logical sequence, not the way they are written.

2. What is difference between WHERE and HAVING?

WHERE filters rows before aggregation, while HAVING filters groups after aggregation.

3. What is the use of GROUP BY?

GROUP BY aggregates data across rows with the same values in specified columns, commonly used with aggregate functions.

4. Explain all types of joins in SQL?

INNER JOIN: Returns matching rows from both tables.
LEFT JOIN: All rows from the left, matched rows from right.
RIGHT JOIN: All rows from the right, matched rows from left.
FULL JOIN: All rows from both, with NULLs where no match.
SELF JOIN: Joins table to itself.
CROSS JOIN: Cartesian product of both tables.

5. What are triggers in SQL?

Triggers are procedural code executed automatically in response to certain events on a table or view (INSERT, UPDATE, DELETE).

6. What is stored procedure in SQL?

A stored procedure is a set of SQL statements saved and executed on demand, useful for modularizing code.

7. Explain all types of window functions?

RANK(): Gives rank with gaps.
DENSE_RANK(): Ranks without gaps.
ROW_NUMBER(): Unique row index.
LEAD(): Access next row.
LAG(): Access previous row.

8. What is difference between DELETE and TRUNCATE?

DELETE: Row-wise deletion, can have WHERE clause, logs each row.
TRUNCATE: Deletes all rows, faster, minimal logging, cannot rollback easily.

9. What is difference between DML, DDL and DCL?

DML: Data Manipulation Language (SELECT, INSERT, UPDATE, DELETE).
DDL: Data Definition Language (CREATE, ALTER, DROP).
DCL: Data Control Language (GRANT, REVOKE).

10. What are aggregate functions?

Functions that return a single value: SUM(), AVG(), COUNT(), MIN(), MAX().

11. Which is faster: CTE or Subquery?

Performance depends on context, but subqueries are sometimes faster as CTEs may be materialized.

12. What are constraints and types?

Rules to maintain data integrity. Types: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT.

13. Types of Keys?

Primary Key
Foreign Key
Unique Key
Composite Key
Candidate Key

14. Different types of Operators?

Arithmetic: +, -, *, /
Comparison: =, <>, >, <, >=, <=
Logical: AND, OR, NOT
Bitwise, LIKE, IN, BETWEEN

15. Difference between GROUP BY and WHERE?

WHERE filters before aggregation. GROUP BY groups after filtering.

16. What are Views?

Virtual tables based on SQL queries. They store only query definition.

17. What are different types of constraints?

Same as Q12: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT.

18. What is difference between VARCHAR and NVARCHAR?

VARCHAR: ASCII, 1 byte per char.
NVARCHAR: Unicode, 2 bytes per char, supports multiple languages.

19. Similarity for CHAR and NCHAR?

CHAR: Fixed-length ASCII.
NCHAR: Fixed-length Unicode.

20. What are indexes and their types?

Used for faster retrieval.

Types:
- Clustered
- Non-clustered
- Unique
- Composite
- Full-text

21. What is an index? Explain its types.

Same as above. Indexes speed up queries by creating pointers to data.

22. List different types of relationships in SQL.

One-to-One
One-to-Many
Many-to-Many

23. Differentiate between UNION and UNION ALL.

UNION: Removes duplicates.
UNION ALL: Includes duplicates.

24. How many types of clauses in SQL?

Common clauses: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET, JOIN, ON.

25. What is the difference between UNION and UNION ALL in SQL?

Same as Q23.

26. What are various types of relationships in SQL?
Same as Q22.

27. Difference between Primary Key and Secondary Key?

Primary Key: Uniquely identifies rows.
Secondary Key: May not be unique, used for lookup.

Credits: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v/1000
  • ❤ 4
More from @dataanalystinterview
  1. Oct 10, 2026📢 Advertising in this channel You can place an ad via Telega․io. It takes just a few minu…
  2. Oct 9, 2026✅SQL Roadmap: Step-by-Step Guide to Master SQL 🧠💻 Whether you're aiming to be a backend…
  3. Oct 9, 2026🇮🇳 𝗚𝗢𝗩𝗘𝗥𝗡𝗠𝗘𝗡𝗧 𝗢𝗙 𝗜𝗡𝗗𝗜𝗔 — 𝗔𝗜𝗖𝗧𝗘 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝟮𝟬𝟮𝟲 🚀…
  4. Oct 8, 2026🎓 𝗠𝗶𝗰𝗿𝗼𝘀𝗼𝗳𝘁 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝘄𝗶𝘁𝗵 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗲𝘀! 🚀🔥 Upgr…
  5. Oct 7, 2026🚀𝗣𝗮𝘆 𝗔𝗳𝘁𝗲𝗿 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 | 𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰…
  6. Oct 7, 2026𝗠𝗮𝘀𝘁𝗲𝗿 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗳𝗼𝗿 𝗙𝗥𝗘𝗘! 🔥 Learn Power BI through these FREE learnin…
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 →