← Back to Interview List

15 SQL Interview Questions

15 SQL Interview Questions TO GET YOU HIRED in 2025 interview.

Interviewer What is the difference between DBMS and RDBMS?
You DBMS (Database Management System) stores data in files without connecting them, so there is no relation between the data. RDBMS (Relational Database Management System), like MySQL, stores data in tables with relationships between them. RDBMS is optimized for large data, supports multiple users, reduces redundancy, and enforces security.
Interviewer What is a Primary Key and a Foreign Key?
You A Primary Key is a unique identifier for each record in a table, cannot be NULL, and is always unique. A Foreign Key is a field in one table that links to the Primary Key in another, creating relationships and ensuring data integrity between tables.
Interviewer What are constraints and their types?
You Constraints enforce rules for data in SQL tables. Key types are: NOT NULL (cannot be empty), UNIQUE (no duplicates allowed), PRIMARY KEY (unique + not null), FOREIGN KEY (connects two tables), CHECK (enforces a condition like age > 18), and DEFAULT (assigns default value if none is provided).
Interviewer What are DDL and DML commands in SQL?
You DDL (Data Definition Language) commands define and modify table structures, like CREATE, ALTER, and DROP. DML (Data Manipulation Language) commands deal with the data, like INSERT, UPDATE, and DELETE.
Interviewer What is the difference between DELETE, DROP, and TRUNCATE statements?
You DELETE removes selected rows based on a condition and can be rolled back. TRUNCATE removes all rows, keeps the table but is not usually reversible. DROP deletes the entire table structure and all data permanently.
Interviewer Differentiate between GROUP BY and ORDER BY clauses.
You GROUP BY groups rows that have the same values for computation (like counting employees per department), typically with aggregate functions. ORDER BY sorts the rows based on one or more columns (like salary descending); it just changes order, not grouping.
Interviewer Explain the difference between WHERE and HAVING clauses.
You WHERE filters rows before grouping (e.g., filter age >= 18). HAVING filters groups after applying GROUP BY, often using aggregate results (like show only departments with more than 10 employees).
Interviewer What are aggregate functions in SQL?
You Aggregate functions include COUNT (number of rows), SUM (total), AVG (average), MIN (minimum), and MAX (maximum). They operate on data columns across multiple rows and return a single summary value.
Interviewer Explain indexing in SQL and what is a clustered index?
You An index speeds up search queries in a database by allowing rapid access to rows. A clustered index sorts and stores data rows in the table based on the index key. Each table can have only one clustered index, usually the primary key.
Interviewer What is normalization and explain its types of normal forms?
You Normalization organizes data to reduce redundancy. First Normal Form (1NF) ensures atomic columns; Second Normal Form (2NF) requires all non-key attributes depend on the full primary key; Third Normal Form (3NF) removes transitive dependencies; BCNF further splits for every determinant to be a candidate key.
Interviewer What do you mean by UNION and UNION ALL operators?
You UNION combines results from two SELECT statements and removes duplicates. UNION ALL does the same but keeps duplicates in the final output.
Interviewer How can you find the second highest salary in a table?
You You can use a subquery: SELECT MAX(salary) FROM employee WHERE salary < (SELECT MAX(salary) FROM employee); To get the name and salary: SELECT name, salary FROM employee WHERE salary = (SELECT MAX(salary) FROM employee WHERE salary < (SELECT MAX(salary) FROM employee));
Interviewer What are views in SQL?
You A VIEW is a virtual table based on a query, which shows selected data from one or more tables without storing it physically. Example: CREATE VIEW view_name AS SELECT ... FROM ...;
Interviewer How can you convert text into date format in SQL?
You You can use the STR_TO_DATE() function. Example: SELECT STR_TO_DATE('27102024', '%d%m%Y'); This converts string "27102024" to date "2024-10-27".
Interviewer What are triggers in SQL?
You A trigger is an automated process that runs in response to certain events on a table, like INSERT, UPDATE, or DELETE. Triggers can update stock when a sale happens, log changes, or enforce rules.