50 SQL Interview Questions
1. What is SQL, and how does it work?
2. What is the difference between DROP, DELETE, and TRUNCATE commands?
3. Define a foreign key and its role in database relationships.
4. What is a NULL value in SQL? How is it different from zero or blank space?
5. What is the difference between DISTINCT and GROUP BY?
6. How can you sort data using SQL?
7. What are constraints in SQL, and name their types.
8. Explain the difference between INNER JOIN and OUTER JOIN.
9. What are SQL aliases? Provide examples.
10. What is a composite key?
11. What are the different types of subqueries in SQL?
12. Explain the concept of AUTO_INCREMENT.
13. What is the difference between RANK() and DENSE_RANK()?
14. How would you combine data from multiple tables using SQL?
15. What is the difference between UNION and UNION ALL?
16. How would you find the nth highest salary in a table?
17. Explain the concept of ACID properties in databases.
18. What are triggers in SQL? Explain their types.
19. Write a trigger to log data into an audit table whenever a record is updated.
20. How do you disable or drop a trigger in SQL?
21. What are the advantages and disadvantages of using triggers?
22. How do you handle performance tuning for SQL queries?
23. Write a query to find duplicate rows in a table.
24. Explain database indexing. When would you not use an index?
25. How do you deal with transactions in SQL?
26. Write a query to find employees earning more than the average salary.
27. How would you get the top 3 records in each group using SQL?
28. Write a query to delete duplicate rows while keeping one instance.
29. Retrieve records from a table where a column value ends with a specific string.
30. Write a query to calculate the percentage contribution of each employees salary to the total
salary.
31. How do you update data in one table based on values in another table?
32. Write a query to find all the managers who have no subordinates.
33. Write a query to find employees who joined in the last 30 days.
34. How do you calculate the difference between two dates in SQL?
35. Retrieve all the employees who share the same department as John.
36. What are stored functions and their advantages?
37. How do you handle NULL values in SQL queries?
38. What is the difference between DELETE and UPDATE?
39. How would you enforce referential integrity in SQL?
40. Write a query to find the second-highest salary in a table.
41. How would you pivot data in SQL?
42. Write a query to calculate the cumulative sum of a column.
43. Retrieve records where a column value starts with 'A'.
44. Write a query to find employees who work in more than one department.
45. How do you join three tables using SQL?
46. Write a query to find employees with duplicate email IDs.
47. Retrieve records of employees whose salaries are between 50,000 and 100,000.
48. Write a query to count the number of employees in each department.
49. How do you sort data by multiple columns in SQL?
50. What is a stored procedure, and how is it different from a function?