0% found this document useful (0 votes)
13 views

SQL Interview Questions

The document provides a comprehensive guide for preparing for SQL-related questions in Data Analyst interviews, detailing 25 essential SQL questions and their answers. Key topics include differences between DDL and DML, types of joins, constraints, and the importance of ACID properties in transactions. It emphasizes the necessity of understanding core database concepts to effectively solve data challenges in real-world scenarios.

Uploaded by

Lohitha Thota
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

SQL Interview Questions

The document provides a comprehensive guide for preparing for SQL-related questions in Data Analyst interviews, detailing 25 essential SQL questions and their answers. Key topics include differences between DDL and DML, types of joins, constraints, and the importance of ACID properties in transactions. It emphasizes the necessity of understanding core database concepts to effectively solve data challenges in real-world scenarios.

Uploaded by

Lohitha Thota
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

INTERVIEW PREP

SQL QUESTIONS
FOR
DATA ANALYST ROLES
VARUN SAGAR THEEGALA
SQL IS
EVERYWHERE

If you’re about to appear for a Data


Analyst interview, you’re certainly going
to be grilled in SQL.

SQL is at the core of any data analyst’s


job.

So definitely interviewers will test your


foundations in the database language.

Hence, it’s crucial to know what are the


concepts you’ll more certainly
encounter in these situations.

VARUN SAGAR THEEGALA


SO HERE ARE 25
QUESTIONS YOU
SHOULD BE
PREPARED
FOR
(With The Answers)

VARUN SAGAR THEEGALA


1. What is DDL and DML? What
is the difference?

ANSWER ->

DDL (Data Definition Language) is


used to define the structure of the
database (e.g., CREATE TABLE, ALTER
TABLE, DROP TABLE).

DML (Data Manipulation Language)


is used to manipulate the data
within the database (e.g., INSERT,
UPDATE, DELETE, SELECT).

VARUN SAGAR THEEGALA


2. What is the difference between
Truncate vs Delete vs Drop?

ANSWER ->

Truncate removes all rows from a


table quickly. It cannot be rolled
back.

Delete removes specific rows from a


table based on a condition. It can be
rolled back.

Drop removes the entire table and


its structure from the database. It
cannot be rolled back.

VARUN SAGAR THEEGALA


3. When is Group By used?

ANSWER ->

The GROUP BY clause is used with


aggregate functions (like SUM, AVG,
COUNT) to group rows based on one or
more columns and perform
calculations within each group.

VARUN SAGAR THEEGALA


4. What is the difference between
Where clause vs. Having clause?

ANSWER ->

Where clause filters rows before


grouping and aggregation.

Having clause filters groups after


grouping and aggregation.

VARUN SAGAR THEEGALA


5. What are Scalar and Aggregate
functions in SQL?

ANSWER ->

Scalar functions return a single


value for each row (e.g., UPPER,
LOWER, SUBSTRING).

Aggregate functions return a single


value for a group of rows (e.g., SUM,
AVG, COUNT, MAX, MIN).

VARUN SAGAR THEEGALA


6. What does coalesce function do
in SQL?

ANSWER ->

The COALESCE function returns the first


non-null value in a list of arguments.

VARUN SAGAR THEEGALA


7. What are Constraints? How
many Constraints are there?

ANSWER ->

Constraints are rules that enforce


data integrity in a database.

Some common constraints include


PRIMARY KEY, FOREIGN KEY, UNIQUE,
NOT NULL, CHECK.

VARUN SAGAR THEEGALA


8. How many primary key and
unique key can be in a table?

ANSWER ->

A table can have only one PRIMARY


KEY constraint.

A table can have multiple UNIQUE


constraints.

VARUN SAGAR THEEGALA


9. What are Joins in SQL. Types of
Joins in SQL?

ANSWER ->

Joins combine data from two or


more tables based on a related
column.

Common types include INNER JOIN,


LEFT JOIN, RIGHT JOIN, FULL OUTER
JOIN, and CROSS JOIN.

VARUN SAGAR THEEGALA


10. Difference between UNION and
UNION ALL

ANSWER ->

UNION combines the results of two


or more SELECT statements,
removing duplicate rows.

UNION ALL combines the results of


two or more SELECT statements,
including duplicate rows.

VARUN SAGAR THEEGALA


11. What is the order of execution
in SQL Code?

ANSWER ->

The general order of execution is: FROM,


WHERE, GROUP BY, HAVING, SELECT,
ORDER BY.

VARUN SAGAR THEEGALA


12. How many Joins is required to
join 8 tables?

ANSWER ->

To join 8 tables, you would typically


require 7 joins.

VARUN SAGAR THEEGALA


13. What are Window Functions or
Analytical functions?

ANSWER ->

Window functions perform calculations


across a set of rows related to the
current row, such as ranking,
partitioning, and calculating running
totals.

VARUN SAGAR THEEGALA


14. What is the diff between Rank
& Dense Rank Function?

ANSWER ->

Rank assigns a rank to each row


within a partition, with gaps for ties.

Dense Rank assigns a rank to each


row within a partition, without gaps
for ties.

VARUN SAGAR THEEGALA


15. What is View? How it is
different from Table?

ANSWER ->

A view is a virtual table that is


created from the result of an SQL
query.

It doesn't physically store data but


provides a dynamic view of the
underlying data.

VARUN SAGAR THEEGALA


16. What is Index?

ANSWER ->

An index is a data structure that


improves the speed of data retrieval
by creating a sorted order for
specific columns in a table.

VARUN SAGAR THEEGALA


17. What is CTE? How it is useful?

ANSWER ->

A Common Table Expression (CTE) is


a temporary named result set that
you can define within a SELECT,
INSERT, UPDATE, or DELETE statement.

CTEs can make complex queries


more readable and maintainable.

VARUN SAGAR THEEGALA


18. What is difference between
SQL vs. PLSQL?

ANSWER ->

SQL (Structured Query Language) is


used to interact with databases,
primarily for data retrieval and
manipulation.

PL/SQL (Procedural Language/SQL)


is an extension of SQL that adds
procedural programming
capabilities to SQL, such as loops,
conditional statements, and
variables.

VARUN SAGAR THEEGALA


19. What is the use case of Cross
Join?

ANSWER ->

CROSS JOIN is used to create a


Cartesian product (all possible
combinations) of rows from two
tables.

It is often used in conjunction with


other clauses (like WHERE) to filter
the results.

VARUN SAGAR THEEGALA


20. Explain the ACID properties of
transactions and their importance.

ANSWER ->

ACID stands for Atomicity, Consistency,


Isolation, and Durability. These
properties ensure the reliability and
integrity of database transactions.

Atomicity: All-or-nothing execution of a


transaction.
Consistency: Maintains database integrity
after a transaction.
Isolation: Transactions are independent and
do not interfere with each other.
Durability: Committed changes are
permanent and survive system failures.

VARUN SAGAR THEEGALA


21. Describe the difference
between a Primary & Foreign Key.

ANSWER ->

Primary Key: A unique identifier for


each row in a table. It cannot
contain null values and must be
unique for every record.

Foreign Key: A column in one table


that references the Primary Key of
another table. It establishes a
relationship between the two tables.

VARUN SAGAR THEEGALA


22. How do Indexes work in a
database?

ANSWER ->

Indexing stores a sorted list of values for


one or more columns, along with pointers
to the actual data rows.

Benefits:
Significantly improves query performance,
especially for searches, joins, and sorting.
Enables faster data retrieval and updates.

Drawbacks:
Increased storage space required for the
index.
Can slow down data insertion and updates
as the index needs to be maintained.

VARUN SAGAR THEEGALA


23. Explain the concept of
normalization in database design.

ANSWER ->

Normalization is the process of


organizing data in a database to
minimize redundancy and improve
data integrity. It involves breaking down
large tables into smaller, more
manageable tables with well-defined
relationships.

Why is it important:
Improves data consistency and reduces the
risk of data anomalies.
Makes data easier to maintain and update.
Improves query performance.

VARUN SAGAR THEEGALA


24. Explain Subqueries & its
different types with examples.

ANSWER ->

Subqueries are nested SELECT


statements within another SQL
statement.

Scalar Subquery: Returns a single value (e.g.,


used in WHERE clause to compare a column
value with the result of the subquery).

Correlated Subquery: References a column


from the outer query within the subquery.

Multiple-Row Subquery: Returns multiple


rows (e.g., used with IN or EXISTS operators).

VARUN SAGAR THEEGALA


25. Explain left join, right join, and
full outer join with examples.

ANSWER ->
LEFT JOIN: Returns all rows from the left table
and matching rows from the right table. If
there is no match in the right table, NULL
values are returned for the right table's
columns.

RIGHT JOIN: Returns all rows from the right


table and matching rows from the left table. If
there is no match in the left table, NULL values
are returned for the left table's columns.

FULL OUTER JOIN: Returns all rows from both


tables. If there is no match in either table,
NULL values are returned for the missing
columns.

VARUN SAGAR THEEGALA


CONCLUSION

A strong foundation in SQL theory is not


just about answering interview
questions.

It's about demonstrating your


understanding of core database
concepts and your ability to think
critically and solve complex problems.

By mastering these fundamentals, you'll


be well-equipped to tackle real-world
data challenges and excel as a data
analyst.

VARUN SAGAR THEEGALA

You might also like