SQL Interview Guide for Freshers
1. What is SQL?
SQL (Structured Query Language) is used to store, manipulate, and retrieve data from relational
databases.
Example: SELECT * FROM employees;
2. Types of SQL Commands
DDL – CREATE, ALTER, DROP, TRUNCATE
DML – INSERT, UPDATE, DELETE
DQL – SELECT
DCL – GRANT, REVOKE
TCL – COMMIT, ROLLBACK
3. Basic Table Creation
CREATE TABLE student (id INT PRIMARY KEY, name VARCHAR(50), age INT);
4. Insert Data
INSERT INTO student VALUES (1,'Rahul',20);
5. Select Syntax
SELECT column_name FROM table_name;
SELECT * FROM student;
6. WHERE Clause
SELECT * FROM student WHERE age > 20;
7. Aggregate Functions
COUNT(), SUM(), AVG(), MIN(), MAX()
Example: SELECT AVG(salary) FROM employees;
8. GROUP BY
SELECT department, COUNT(*) FROM employees GROUP BY department;
9. JOIN Types
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL JOIN
10. Example JOIN
SELECT [Link], c.course_name FROM student s JOIN course c ON s.course_id=c.course_id;
11. Primary Key
A unique identifier for each record in a table.
12. Foreign Key
A column that links two tables.
13. Difference Between DELETE, TRUNCATE, DROP
DELETE – removes specific rows
TRUNCATE – removes all rows quickly
DROP – removes entire table
14. Index
Used to speed up query performance.
15. View
A virtual table based on a query.
Common SQL Interview Questions
Question Answer
What is a primary key? A column that uniquely identifies each row.
What is a foreign key? A key used to link two tables.
What is normalization? Process of organizing data to reduce redundancy.
Difference between WHERE and HAVING? WHERE filters rows before grouping, HAVING filters groups after GROUP BY.
What is a join? Combining rows from two or more tables based on related columns.
What is a subquery? A query inside another query.
What is a view? A virtual table created from a SELECT statement.
What is an index? A database structure used to improve query speed.
Difference between INNER JOIN and LEFT JOIN? INNER returns matching rows, LEFT returns all rows from left table.
What is GROUP BY? Used to group rows with the same values.