Advertisements [adrotate group="1"]

Top 15 SQL Interview Questions and Answers

Top 15 SQL Interview Questions and Answers

Ace your next interview with these top SQL questions and answers! Perfect for beginners & job seekers. Practice smart, get hired faster.

Structured Query Language (SQL) is one of the most important tools for anyone working with databases—whether you’re a data analyst, software developer, or data scientist. It’s often a core part of technical interviews.

In this blog, we’ve compiled some of the most commonly asked SQL interview questions with clear and concise answers to help you ace your next interview.


1. What is SQL?

Answer:
SQL (Structured Query Language) is a standard language used to communicate with relational databases. It is used for tasks such as retrieving, inserting, updating, and deleting data.


2. What is the difference between SQL and MySQL?

Answer:
SQL is the language used for managing and manipulating relational databases.
MySQL is a popular open-source relational database management system that uses SQL to perform database operations.


3. What are the different types of SQL statements?

Answer:

  • DDL (Data Definition Language): CREATE, ALTER, DROP

  • DML (Data Manipulation Language): INSERT, UPDATE, DELETE

  • DQL (Data Query Language): SELECT

  • DCL (Data Control Language): GRANT, REVOKE

  • TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT


4. What is a Primary Key?

Answer:
A primary key is a unique identifier for each record in a table. It must contain unique values and cannot have NULLs.


5. What is a Foreign Key?

Answer:
A foreign key is a field (or group of fields) in one table that refers to the primary key in another table. It is used to maintain referential integrity.


6. What is the difference between WHERE and HAVING?

Answer:

  • WHERE is used to filter rows before grouping.

  • HAVING is used to filter groups after using the GROUP BY clause.


7. What are JOINS in SQL?

Answer:
JOINS are used to combine rows from two or more tables based on related columns.
Common types of joins include:

  • INNER JOIN

  • LEFT JOIN

  • RIGHT JOIN

  • FULL OUTER JOIN

  • SELF JOIN


8. How do you find duplicate records in a table?

sql
SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name
HAVING COUNT(*) > 1;

This query helps identify records that appear more than once.


9. What is a Subquery?

Answer:
A subquery is a query nested inside another query. It can be used in SELECT, INSERT, UPDATE, or DELETE statements.

Example:

sql
SELECT name FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);

10. What is Normalization?

Answer:
Normalization is the process of organizing data to reduce redundancy and improve data integrity.
Common forms:

  • 1NF (First Normal Form)

  • 2NF (Second Normal Form)

  • 3NF (Third Normal Form)

  • BCNF (Boyce-Codd Normal Form)


11. What is the difference between DELETE and TRUNCATE?

Answer:

  • DELETE removes specific rows and can be rolled back.

  • TRUNCATE removes all rows quickly and cannot be rolled back in many systems.


12. What is a View?

Answer:
A view is a virtual table based on the result of an SQL statement. It doesn’t store the data itself but displays data stored in one or more tables.


13. What is the use of GROUP BY clause?

Answer:
GROUP BY is used to arrange identical data into groups. It’s often used with aggregate functions like COUNT(), MAX(), MIN(), AVG(), and SUM().


14. What is an Index?

Answer:
An index is used to speed up the retrieval of data from a database. It’s similar to the index of a book and helps reduce the time taken for query execution.


15. What are Aggregate Functions in SQL?

Answer:
Aggregate functions perform a calculation on a set of values and return a single value. Examples include:

  • COUNT()

  • SUM()

  • AVG()

  • MIN()

  • MAX()


Final Thoughts

Understanding SQL is essential for cracking interviews in data-related roles. While it’s important to memorize syntax, what truly matters is your ability to write and understand real-world queries.

Tips to Ace SQL Interviews:

  • Practice with real datasets (e.g., on Kaggle or SQL Zoo)

  • Master joins and subqueries

  • Get comfortable with writing nested queries and CTEs

  • Revise database concepts like normalization and indexing

Brillica Services

Leave a Reply

    © 2024 Crivva - Business Promotion. All rights reserved.