SQL Interview Questions and Answers
(Data Analyst)
1. What is SQL?
Answer:
SQL (Structured Query Language) is used to store, retrieve, and manipulate data in databases.
2. What are the different types of SQL commands?
Answer:
DDL (CREATE, ALTER, DROP)
DML (INSERT, UPDATE, DELETE)
DQL (SELECT)
DCL (GRANT, REVOKE)
TCL (COMMIT, ROLLBACK)
3. What is a database?
Answer:
A database is an organized collection of data stored in tables.
4. What is a table?
Answer:
A table stores data in rows and columns.
5. What is a primary key?
Answer:
A primary key uniquely identifies each row in a table and cannot have NULL values.
6. What is a foreign key?
Answer:
A foreign key is a column that creates a relationship between two tables.
7. What is the SELECT statement?
Answer:
The SELECT statement is used to retrieve data from a table.
8. What is WHERE clause?
Answer:
The WHERE clause is used to filter records based on conditions.
9. What is the difference between WHERE and HAVING?
Answer:
WHERE: Filters rows before grouping
HAVING: Filters data after GROUP BY
10. What is GROUP BY?
Answer:
GROUP BY is used to group rows with the same values and apply aggregate functions.
11. What are aggregate functions?
Answer:
Functions that perform calculations on multiple rows, such as:
COUNT(), SUM(), AVG(), MIN(), MAX()
12. What is ORDER BY?
Answer:
ORDER BY is used to sort the result in ascending or descending order.
13. What is JOIN in SQL?
Answer:
JOIN is used to combine data from two or more tables.
14. Types of JOINs in SQL?
Answer:
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL JOIN
15. What is INNER JOIN?
Answer:
INNER JOIN returns only matching records from both tables.
16. What is LEFT JOIN?
Answer:
LEFT JOIN returns all records from the left table and matching records from the right table.
17. What is NULL value?
Answer:
NULL means missing or unknown data.
18. What is the difference between DELETE and
TRUNCATE?
Answer:
DELETE: Removes specific rows (can rollback)
TRUNCATE: Removes all rows (cannot rollback)
19. What is a subquery?
Answer:
A subquery is a query written inside another query.
20. What is DISTINCT keyword?
Answer:
DISTINCT is used to remove duplicate values from the result.