TGViewer
Data Analytics Data Analytics @sqlspecialist · 111K subscribers
Post #2461 9.01K
✅ Top SQL Interview Questions with Answers: Part-1 🧠

1. What is SQL and why is it used?
SQL (Structured Query Language) is used to manage and manipulate relational databases. It allows users to retrieve, insert, update, and delete data efficiently.

2. Difference between SQL and MySQL
- SQL is a language used to interact with databases.
- MySQL is a relational database management system (RDBMS) that uses SQL.

Think of SQL as the language, and MySQL as the software that understands and processes it.

3. What are primary keys and foreign keys? 🔑
- Primary Key uniquely identifies each row in a table. It must be unique and not null.
- Foreign Key links one table to another. It references the primary key of another table to maintain referential integrity.

4. What is a unique constraint?
It ensures that all values in a column (or combination of columns) are unique across the table. Unlike primary keys, columns with a unique constraint can accept one NULL.

5. Difference between WHERE and HAVING
- WHERE filters rows before aggregation.
- HAVING filters groups after aggregation.
Example: Use WHERE for filtering raw data, HAVING for filtering GROUP BY results.

6. What are joins? Types of joins? 🤝
Joins combine data from multiple tables based on related columns.
Types:
- INNER JOIN – Returns matching rows
- LEFT JOIN – All rows from left table + matched rows from right
- RIGHT JOIN – All rows from right table + matched from left
- FULL JOIN – All rows from both tables
- CROSS JOIN – Cartesian product

7. Difference between INNER JOIN and LEFT JOIN
- INNER JOIN only returns rows with matching keys in both tables.
- LEFT JOIN returns all rows from the left table, plus matching rows from the right table (NULLs if no match).

8. What is a subquery?
A subquery is a query nested inside another SQL query. It can be used in SELECT, FROM, or WHERE clauses to fetch intermediate results.

9. What are CTEs (Common Table Expressions)?
CTEs are temporary named result sets that make queries more readable and reusable.
Syntax:
WITH cte_name AS (  
SELECT ...
)
SELECT * FROM cte_name;


10. What is a view in SQL?
A view is a virtual table based on a SQL query. It doesn't store data itself but provides a way to simplify complex queries, improve security, and reuse logic.

Double Tap ❤️ For Part-2
  • ❤ 58
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 →