📌 SQL / RDBMS Interview Questions & Answers
✅ Basics
Q1. Difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN?
INNER JOIN: returns only matching rows from both tables.
LEFT JOIN: all rows from left + matching rows from right.
RIGHT JOIN: all rows from right + matching rows from left.
FULL OUTER JOIN: all rows from both sides, with NULL where no match.
Q2. What is the difference between DELETE, TRUNCATE, and DROP?
DELETE: removes rows, can use WHERE, logged, can rollback.
TRUNCATE: removes all rows, faster, minimal logging, can’t use WHERE.
DROP: removes the table structure itself.
Q3. What are constraints in SQL?
NOT NULL – disallows null values
UNIQUE – ensures all values in column are unique
PRIMARY KEY – unique + not null
FOREIGN KEY – ensures referential integrity
CHECK – enforces condition
DEFAULT – provides default value
Q4. Difference between WHERE and HAVING?
WHERE: filters rows before aggregation
HAVING: filters groups after aggregation
Example:
SELECT dept, COUNT(*)
FROM employees
WHERE salary > 50000
GROUP BY dept
HAVING COUNT(*) > 5;