आज के समय में IT सेक्टर, डेटा एनालिस्ट, सॉफ्टवेयर डेवलपर और बैकएंड डेवलपर की लगभग हर जॉब में SQL Interview Questions and Answers एक अहम भूमिका निभाते हैं। चाहे आप फ्रेशर हों या एक्सपीरियंस्ड प्रोफेशनल, SQL से जुड़े सवाल इंटरव्यू में जरूर पूछे जाते हैं।
इस ब्लॉग पोस्ट में हमने SQL के सबसे महत्वपूर्ण और बार-बार पूछे जाने वाले इंटरव्यू प्रश्नों को आसान भाषा में समझाया है, ताकि आप कॉन्सेप्ट को जल्दी समझ सकें और आत्मविश्वास के साथ इंटरव्यू दे सकें। यह कंटेंट खासतौर पर उन उम्मीदवारों के लिए तैयार किया गया है जो IT जॉब, डेटा प्रोफाइल या टेक्निकल इंटरव्यू की तैयारी कर रहे हैं।
Basic SQL Interview Questions
1. What is SQL?
SQL (Structured Query Language) is a standard language used to store, retrieve, update, and manage data in relational database management systems such as MySQL, Oracle, PostgreSQL, and SQL Server.
2. What are the types of SQL commands?
- DDL (Data Definition Language): CREATE, ALTER, DROP, TRUNCATE
- DML (Data Manipulation Language): INSERT, UPDATE, DELETE
- DQL (Data Query Language): SELECT
- DCL (Data Control Language): GRANT, REVOKE
- TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT
3. What is a Primary Key?
A Primary Key is a column or a set of columns that uniquely identifies each record in a table. It does not allow NULL values and must contain unique values.
4. What is a Foreign Key?
A Foreign Key is a column that creates a relationship between two tables. It refers to the Primary Key of another table.
5. Difference between DELETE, TRUNCATE, and DROP?
| DELETE | TRUNCATE | DROP |
|---|---|---|
| Deletes selected rows | Deletes all rows | Deletes entire table |
| Rollback possible | Rollback not possible | Rollback not possible |
| Slower | Faster | Fastest |
Intermediate SQL Interview Questions
6. What is JOIN?
JOIN is used to combine rows from two or more tables based on a related column between them.
7. Types of JOINs
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- FULL JOIN
- CROSS JOIN
8. Difference between WHERE and HAVING?
WHERE clause filters rows before grouping, while HAVING clause filters grouped data after GROUP BY.
9. What is GROUP BY?
GROUP BY groups rows with the same values and is commonly used with aggregate functions such as COUNT, SUM, AVG.
10. What are Aggregate Functions?
Aggregate functions perform calculations on multiple rows and return a single value.
Examples include COUNT(), SUM(), AVG(), MAX(), and MIN().
Advanced SQL Interview Questions
11. What is an Index?
An Index is used to improve the performance of SELECT queries by reducing the amount of data scanned.
12. What is Normalization?
Normalization is the process of organizing data to reduce redundancy and improve data integrity.
13. What is Denormalization?
Denormalization is the process of adding redundancy to improve query performance.
14. What is a View?
A View is a virtual table created using a SELECT query. It does not store data physically.
15. What is ACID Property?
- Atomicity: Transaction is all or nothing
- Consistency: Data remains consistent
- Isolation: Transactions execute independently
- Durability: Data persists after commit
SQL Query Based Interview Questions
16. How to find the second highest salary?
SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees);
17. Difference between UNION and UNION ALL?
UNION removes duplicate records, while UNION ALL keeps duplicate records and performs faster.
18. What is a Stored Procedure?
A Stored Procedure is a precompiled collection of SQL statements stored in the database.
19. What is a Trigger?
A Trigger is automatically executed when an INSERT, UPDATE, or DELETE operation occurs.
20. Difference between CHAR and VARCHAR?
CHAR stores fixed-length strings, whereas VARCHAR stores variable-length strings and saves memory.
Tricky SQL Interview Questions and Answers (Confusing & Conceptual)
1. What is the difference between WHERE and ON clause?
Confusion Point: Both are used with JOIN.
Answer:
WHERE clause filters rows after JOIN execution, while ON clause defines the JOIN condition during table joining.
2. Is NULL equal to NULL in SQL?
Confusion Point: Many candidates think NULL = NULL is true.
Answer:
No. NULL represents an unknown value, so NULL = NULL returns FALSE.
Use IS NULL instead.
3. COUNT(*) vs COUNT(column_name) – are they same?
Answer:
- COUNT(*): Counts all rows including NULL values
- COUNT(column_name): Counts only non-NULL values
4. Can we use GROUP BY without aggregate functions?
Confusion Point: Many think aggregate functions are mandatory.
Answer:
Yes, GROUP BY can be used without aggregate functions to remove duplicate records.
5. What will happen if WHERE is used with aggregate functions?
Answer:
WHERE cannot be used directly with aggregate functions.
Use HAVING instead.
6. Which is faster: Subquery or JOIN?
Confusion Point: No fixed rule.
Answer:
Generally JOIN performs better, but performance depends on indexing, data size, and query optimizer.
7. What is the difference between UNION and JOIN?
Answer:
- UNION: Combines result sets vertically (rows)
- JOIN: Combines tables horizontally (columns)
8. Can a table have multiple primary keys?
Confusion Point: Composite keys confuse candidates.
Answer:
A table can have only one Primary Key, but it can consist of multiple columns (Composite Key).
9. Difference between DELETE with WHERE and TRUNCATE?
Answer:
- DELETE with WHERE removes specific rows
- TRUNCATE removes all rows and resets identity
10. Can we rollback TRUNCATE?
Answer:
No. TRUNCATE is a DDL command and cannot be rolled back.
11. What is the difference between EXISTS and IN?
Answer:
EXISTS checks for existence of rows and stops after finding one match.
IN compares values and may be slower for large datasets.
12. What happens if ORDER BY is used without ASC or DESC?
Answer:
By default, ORDER BY sorts data in ASCENDING order.
13. Can we use alias in WHERE clause?
Confusion Point: Alias works in SELECT but not WHERE.
Answer:
No. Aliases are not available in WHERE clause.
They can be used in ORDER BY.
14. Difference between RANK() and DENSE_RANK()?
Answer:
- RANK(): Skips ranking numbers
- DENSE_RANK(): Does not skip ranking numbers
15. Is Index always beneficial?
Confusion Point: Index = fast (always) ❌
Answer:
Index speeds up SELECT queries but slows down INSERT, UPDATE, and DELETE operations.
Interview Tip
Most interviewers use such confusing SQL questions to test concept clarity, not syntax.
Conclusion
These SQL interview questions and answers are useful for freshers as well as experienced candidates preparing for database-related interviews.
हमें उम्मीद है कि यह SQL Interview Questions and Answers की लिस्ट आपकी इंटरव्यू तैयारी में मददगार साबित होगी। SQL की अच्छी समझ न केवल इंटरव्यू क्लियर करने में मदद करती है, बल्कि आपकी प्रोफेशनल ग्रोथ के लिए भी जरूरी है।
अगर आप इन सवालों को नियमित रूप से प्रैक्टिस करते हैं और इनके पीछे के कॉन्सेप्ट को समझते हैं, तो किसी भी SQL इंटरव्यू में अच्छा प्रदर्शन कर सकते हैं। ऐसी ही और उपयोगी स्टडी मटीरियल, नोट्स और प्रैक्टिस प्रश्नों के लिए हमारी वेबसाइट को जरूर विज़िट करते रहें।