50 Basic SQL Interview Questions and Answers
1. What is SQL?
Answer: SQL is a language for accessing and managing data in relational databases.
2. What is a database?
Answer: A database is an organized collection of structured data stored electronically.
3. What is a table in SQL?
Answer: A table is a collection of rows and columns where data is stored.
4. What is a field?
Answer: A field is a column in a table, representing a specific attribute.
5. What is a record?
Answer: A record is a row in a table, containing related data.
6. What is a primary key?
Answer: A primary key uniquely identifies each record in a table.
7. What is a foreign key?
Answer: A foreign key is a field that creates a link between two tables.
8. What is a constraint in SQL?
Answer: Constraints enforce rules on data, like NOT NULL, UNIQUE, CHECK, PRIMARY KEY, and
FOREIGN KEY.
9. What is a NULL value?
Answer: NULL means a field has no value (not zero or blank).
10. What is the use of the SELECT statement?
Answer: Used to retrieve data from one or more tables.
11. What are the types of SQL statements?
Answer: DDL: CREATE, ALTER, DROP; DML: SELECT, INSERT, UPDATE, DELETE; DCL: GRANT,
REVOKE; TCL: COMMIT, ROLLBACK, SAVEPOINT
12. What is the INSERT command?
Answer: Adds new records to a table.
13. What is the UPDATE command?
Answer: Modifies existing records in a table.
Page 1
50 Basic SQL Interview Questions and Answers
14. What is the DELETE command?
Answer: Removes specific rows from a table.
15. What is the CREATE command?
Answer: Creates a new table or database.
16. What is the DROP command?
Answer: Deletes a table or database.
17. What is the ALTER command?
Answer: Modifies an existing table structure.
18. What is the TRUNCATE command?
Answer: Deletes all rows from a table quickly and cannot be rolled back.
19. What is the difference between DELETE and TRUNCATE?
Answer: DELETE: Row-wise removal, can be rolled back. TRUNCATE: Removes all rows, faster, cannot be
rolled back.
20. What is the difference between DROP and DELETE?
Answer: DROP: Deletes table and data. DELETE: Deletes only data.
21. What is a JOIN?
Answer: Combines rows from two or more tables based on a related column.
22. What is an INNER JOIN?
Answer: Returns only matching rows from both tables.
23. What is a LEFT JOIN?
Answer: Returns all rows from the left table and matched rows from the right table.
24. What is a RIGHT JOIN?
Answer: Returns all rows from the right table and matched rows from the left table.
25. What is a FULL JOIN?
Answer: Returns all rows when there is a match in either left or right table.
26. What is a SELF JOIN?
Answer: A table is joined with itself.
27. What is a CROSS JOIN?
Page 2
50 Basic SQL Interview Questions and Answers
Answer: Returns a Cartesian product (every row in one table with every row in the other).
28. What is the difference between INNER and OUTER JOIN?
Answer: INNER: Only matched rows. OUTER: Includes unmatched rows too.
29. Write a basic INNER JOIN query.
Answer: SELECT a.name, b.order_id FROM customers a INNER JOIN orders b ON a.customer_id =
b.customer_id;
30. What happens if there is no match in LEFT JOIN?
Answer: The result will show NULL for the unmatched columns from the right table.
31. What is the WHERE clause?
Answer: Filters rows based on conditions.
32. What is the HAVING clause?
Answer: Filters groups after aggregation (used with GROUP BY).
33. What is the difference between WHERE and HAVING?
Answer: WHERE: Before grouping. HAVING: After grouping.
34. What is GROUP BY?
Answer: Groups rows with the same values.
35. What is ORDER BY?
Answer: Sorts the result set in ascending or descending order.
36. What are aggregate functions?
Answer: Functions like COUNT(), SUM(), AVG(), MIN(), MAX().
37. How do you find the total number of records in a table?
Answer: SELECT COUNT(*) FROM table_name;
38. How to find the average of a column?
Answer: SELECT AVG(salary) FROM employees;
39. What does the LIKE operator do?
Answer: Used for pattern matching with % and _.
40. What does BETWEEN operator do?
Answer: Filters values within a range.
Page 3
50 Basic SQL Interview Questions and Answers
41. What is a view?
Answer: A virtual table based on a query result.
42. What is an index?
Answer: Improves the speed of data retrieval.
43. What is a subquery?
Answer: A query inside another query.
44. What is a stored procedure?
Answer: A set of SQL statements saved for reuse.
45. What is a trigger?
Answer: A block of code that runs automatically when a specific event occurs (like INSERT or DELETE).
46. What is a transaction?
Answer: A group of SQL statements treated as a single unit.
47. What are ACID properties?
Answer: Atomicity, Consistency, Isolation, Durability - ensure reliable transactions.
48. What is the use of DISTINCT?
Answer: Returns unique values only.
49. What is a case statement?
Answer: Used for conditional logic in queries.
50. What is the default sort order in ORDER BY?
Answer: Ascending (ASC).
Page 4