15 SQL Interview Questions TO GET YOU HIRED in 2026 | SQL Interview Questions & Answers |Intellipaat
Summary
Highlights
Normalization organizes data to minimize redundancy and prevent anomalies. Normal forms include: 1NF (atomic values, unique column names), 2NF (non-key attributes depend on primary key), 3NF (no transitive dependencies), and BCNF (every determinant is a candidate key).
SQL is crucial for managing and analyzing data in major companies like Netflix, Meta, Uber, and Google. It is an essential skill for various roles, including developers, data analysts, engineers, and scientists. A strong understanding of SQL is vital for job interviews.
DBMS (Database Management System) is a basic way to store data in files without connections. RDBMS (Relational Database Management System), like MySQL, stores data in interconnected tables, allowing for faster retrieval, reduced redundancy, and high security for large datasets.
A primary key uniquely identifies each row in a table, ensuring distinct, non-duplicate, and non-null values (e.g., a student's roll number). A foreign key links tables by referencing a primary key in another table, enabling connections between related data (e.g., linking student details to course enrollment using roll number).
Constraints are rules that maintain data accuracy and reliability in SQL tables. Types include: NOT NULL (column cannot be empty), UNIQUE (all values in a column are distinct), PRIMARY KEY (combines NOT NULL and UNIQUE), FOREIGN KEY (links tables), CHECK (sets conditions for values), and DEFAULT (assigns a default value if none is specified).
DDL (Data Definition Language) commands define the database structure (e.g., CREATE, ALTER, DROP tables). DML (Data Manipulation Language) commands work with the actual data (e.g., INSERT, UPDATE, DELETE records).
DELETE removes specific rows based on conditions and allows rollback. TRUNCATE quickly clears all data from a table, leaving the structure intact, but cannot be rolled back. DROP removes the entire table structure and its data permanently, with no rollback.
GROUP BY aggregates rows into groups based on specified columns, often used with functions like SUM, AVG, COUNT to get summarized data. ORDER BY sorts the result set in a particular order (ascending or descending) based on one or more columns.
WHERE filters individual rows before any grouping occurs, based on specific conditions. HAVING filters groups created by the GROUP BY clause, based on aggregate results.
UNION combines result sets of two or more SELECT statements, removing duplicate rows. UNION ALL combines result sets without removing duplicates, including all matching rows from both statements.
The second highest salary can be found using nested subqueries. The innermost query finds the maximum salary. The next subquery finds the maximum salary that is less than the overall maximum. The outermost query then selects employees with that specific salary.
A view is a virtual table that doesn't store data but presents data from one or more tables in a specific way. Views can limit sensitive data, restrict user permissions, and simplify complex queries.
To convert a string (text) into a date format, the STRING_TO_DATE function is used. You specify the string and its format pattern (e.g., '%d%m%Y' for day, month, year) to ensure SQL correctly interprets the date.
Triggers are automatic actions that run when a specific event (INSERT, UPDATE, DELETE) occurs on a table in the database. They can be used to update related data, maintain data integrity, or log transactions automatically without manual intervention.
Aggregate functions perform calculations on a set of rows and return a single value. Examples include COUNT (number of rows), SUM (total of a numeric column), AVG (average of a numeric column), MIN (smallest value), and MAX (largest value).
Indexing speeds up data retrieval by creating an organized structure for data. A clustered index physically sorts the data rows in the table based on the index key, allowing for very fast retrieval of data within a specific range.