SQL Guidebook 2025-26 - Nucleus
SQL Guidebook 2025-26 - Nucleus
GUIDEBOOK
Basics to Advanced |
3 Domains | 30+ Practice Queries
Edition 2025-26
ISSUE DETAILS AND COPYRIGHT
© 2025 by Nucleus — The Analytics Society, Shaheed Sukhdev College of Business Studies
All Rights Reserved.
This guidebook is licensed for personal use and is meant for educational purposes only.
No part of this publication may be reproduced or transmitted in any form or by any means electronic, recording, photocopy, or any information storage and retrieval system or
otherwise without prior written permission of the team. For permission requests, write to Nucleus at [email protected]
This guidebook is not to be sold or used by any means for monetary gains.
We’re deeply thankful to past members of Nucleus – whose unwavering support and commitment inspired us to simplify SQL concepts for beginners. This guidebook reflects
the spirit of collaborative learning – we hope it serves as a practical and lasting companion for anyone starting their SQL journey and encourage a deeper appreciation of
database management.
And a heartfelt thanks to our guide, mentors in short beloved & learned seniors:
Aman Bhandari (Houlihan Lokey), Anish Agarwal (Bain Capability Network), Krishang Baldi (YCP Auctus), Jatin Singh (Bain Capability Network), Moksh Ahuja (Nation with NaMo),
Muskan Goyal (Big Bang A.I.), Nancy Garg, Nikhil Jain (D.E. Shaw India), Radhika Singh, Sneha Jindal (Alvarez & Marsal), Uday Arora (Alvarez & Marsal), Vanshika Bhattad (Trinity
Life Sciences), Yash Agarwal (L.E.K. Consulting)
On a final note, ALL THE BEST, we hope this guide makes learning SQL easier and more fun for you. Good luck!
01
Nucleus-The Analytics Society of SSCBS is one of
the most exclusive and prestigious society in the
whole of Delhi University
02 nucleus ki
We focus on enhancing the skill set of the
students in the field of analytics by providing
them with requisite training in various industry group photo
standard applications encompassing MS-Excel,
Power BI, Python, R, Tableau among various
others
03
The society also shares an excellent longstanding
relationship with the corporate sector
04
We have collaborated with firms in context of
taking up live projects, conducting speaker
sessions both within the private and public sector
domains
Dr. Amrina Kausar Dr. Mona Verma Dr. Rishi Rajan Sahay Dr. Satish Kumar Goel
(Associate Professor) (Associate Professor) (Associate Professor) (Assistant Professor)
We extend our heartfelt gratitude to our Teachers-in-Charge — Dr. Amrina Kausar, Dr. Mona Verma, Dr. Rishi Rajan Sahay, and Dr. Satish Kumar Goel — whose unwavering
support and insightful guidance were instrumental in the creation of this SQL Guidebook. Their dedication, patience, and expertise have been a constant source of inspiration
throughout our journey. With their encouragement, we were able to pursue our goals with confidence and clarity.
The mentorship they provided has not only shaped our understanding but has also helped us grow as learners and as a team. Their commitment to fostering a culture of
initiative, learning, and academic excellence has made a lasting impact on our experience at Nucleus.
We remain deeply grateful for the time and effort they invested in our growth. Their belief in the power of student-led learning continues to motivate us to keep pushing
boundaries and striving for better. This guidebook stands as a reflection of their continued encouragement and the values they instilled in us. We thank them sincerely for
being the guiding force behind every step of the way.
INTRODUCTION TO DATABASES
WHAT IS A DATABASE?
A database is an organized collection of data that is stored and accessed electronically. Databases are designed
to manage large amounts of information by allowing users to input, retrieve, and manage data efficiently.
IMPORTANCE OF DATABASE:
Efficient data management: Helps organize and maintain large volumes of data
Quick data retrieval: Allows for fast access and manipulation of data
Data integrity: Ensures accuracy and consistency of data over its lifecycle
TYPES OF DATABASES:
DATABASE SERVERS
SQL SERVERS
DATABASE
CLIENT
DATABASE SCHEMA
WHAT IS A DATABASE SCHEMA?
A schema is a blueprint of a database, outlining how data is organized and interrelated. It defines tables, fields, relationships, and other elements. A visual representation of
this schema is called a schema diagram, showing tables, columns, data types, keys, and relationships.
LOCATION
INTRODUCTION
In MySQL, clauses are components of SQL statements that define conditions, constraints, or modifications on the data being queried or manipulated. They help refine, filter,
group, or sort results within a database operation.
Name Age
SELECTING SPECIFIC COLUMNS
Amit 30
SQL STATEMENT
Priya 25
SELECT NAME, AGE FROM employees; Rahul 35
Sita 28
To select specific columns, instead of an asterisk (*), we enter a list of Vijay 22
columns in the SELECT statement
Anita 33
Each column name is separated from the others by a comma and the
columns are displayed in the order listed Ravi 29
WHERE
SELECT DISTINCT Clause OUTPUT
The SELECT DISTINCT statement is used to return only distinct (different) values. AddressID
Example: 1
SQL STATEMENT 2
3
SELECT DISTINCT AddressID FROM employees;
5
6
WHERE Clause
The WHERE clause is used to filter records in a database. It extracts records that
satisfy a specific condition. ID Name Age AddressID
E. xample: 1 Amit 30 1
SQL STATEMENT 3 Rahul 35 2
4 Sita 28 3
SELECT * FROM employees WHERE Age>25;
6 Anita 33 5
Operator Meaning 7 Ravi 29 6
Numeric values should not be enclosed
= Equal to
in quotes whereas SQL requires text
<> or != Not Equal to values to be enclosed in single quotes
(‘’). Double quotes (“”) are not allowed!
< Less than
<= Less than or equal to The WHERE clause follows the
> Greater than FROM clause
WHERE clause is also used in
>= Greater than or equal to
UPDATE, DELETE etc!
HAVING Clause
The HAVING clause filters records that are grouped by the GROUP BY clause.
It is similar to the WHERE clause, but HAVING is used after grouping the records.
Example:
SQL STATEMENT
AddressID Count
SELECT AddressID, COUNT(*) AS Count
FROM employees 1 2
GROUP BY AddressID 3 2
HAVING COUNT(*) > 1;
INTRODUCTION
What is a SQL Join?
A SQL join is a clause used to combine rows from two or more tables in a database based on a related column (typically a primary key in one table and a foreign key in another)
between them. It allows for the retrieval of related data stored in multiple tables by matching columns that are specified in the join condition.
Inner Join Left Join Right Join Full Join Cross Join Self Join
INNER JOIN
What is an Inner Join?
An INNER JOIN in SQL is a type of join that retrieves only the rows from both tables that have matching values in the specified columns. If there is no match between
the tables, the rows are not included in the result set.
SQL SYNTAX
SQL SYNTAX
ID Name Age Address ID Address ID Country ID Name Age Address ID Address ID Country
1 Amit 30 1 1 INDIA 1 Amit 30 1 1 INDIA
2 Priya 25 1 2 USA 2 Priya 25 1 1 INDIA
3 Rahul 35 2 4 AUSTRALIA 3 Rahul 35 2 2 USA
4 Sita 28 3 6 FRANCE 4 Sita 28 3 NULL NULL
5 Vijay 22 3 7 NEPAL 5 Vijay 22 3 NULL NULL
6 Anita 33 5 8 UK 6 Anita 33 5 NULL NULL
7 Ravi 29 6 9 SPAIN 7 Ravi 29 6 6 FRANCE
SQL SYNTAX
ID Name Age Address ID Address ID Country ID Name Age Address ID Address ID Country
1 Amit 30 1 1 INDIA 1 Amit 30 1 1 INDIA
2 Priya 25 1 2 USA 2 Priya 25 1 1 INDIA
3 Rahul 35 2 4 AUSTRALIA 3 Rahul 35 2 2 USA
4 Sita 28 3 6 FRANCE NULL NULL NULL NULL 4 AUSTRALIA
5 Vijay 22 3 7 NEPAL 7 Ravi 29 6 6 FRANCE
6 Anita 33 5 8 UK NULL NULL NULL NULL 7 NEPAL
7 Ravi 29 6 9 SPAIN NULL NULL NULL NULL 8 UK
NULL NULL NULL NULL 9 SPAIN
SQL SYNTAX
ID Name Age Address ID Address ID Country ID Name Age Address ID Address ID Country
1 Amit 30 1 1 INDIA 1 Amit 30 1 1 INDIA
2 Priya 25 1 1 INDIA
2 Priya 25 1 2 USA
3 Rahul 35 2 2 USA
3 Rahul 35 2 4 AUSTRALIA 4 Sita 28 3 NULL NULL
4 Sita 28 3 6 FRANCE 5 Vijay 22 3 NULL NULL
5 Vijay 22 3 7 NEPAL 6 Anita 33 5 NULL NULL
7 Ravi 29 6 6 FRANCE
6 Anita 33 5 8 UK
NULL NULL NULL NULL 4 AUSTRALIA
7 Ravi 29 6 9 SPAIN NULL NULL NULL NULL 7 NEPAL
NULL NULL NULL NULL 8 UK
NULL NULL NULL NULL 9 SPAIN
Can you provide a list of the top 20 products based on total units sold? We need to identify our most
popular products to ensure we are prioritizing their availability and focusing our marketing efforts on these
items. This data is vital for optimizing our inventory management and promotional strategies.
SELECT
p.Product_ID, We’re selecting each Product_ID and Product_Name, then summing up the total number of units
1 SELECT p.Product_Name, sold (Total_Units_Sold) for each product.
SUM(s.Units) AS Total_Units_Sold
2 FROM FROM sales AS s The data comes from the sales table, which contains details about the units sold.
JOIN products p ON s.Product_ID = We join the sales table with the products table (p) using the Product_ID, so we can retrieve the
3 JOIN p.Product_ID product names corresponding to each sale.
GROUP BY The results are grouped by Product_ID and Product_Name, allowing us to aggregate the total units
4 GROUP BY p.Product_ID, p.Product_Name sold for each product.
ORDER BY We sort the products by Total_Units_Sold in descending order, so the products with the highest
5 ORDER BY Total_Units_Sold DESC sales appear at the top.
6 LIMIT LIMIT 20; Finally, we limit the results to the top 20 products based on total units sold.
Can you provide the total sales in USD for each store over a specified time period? We need to assess which stores
are performing the best and identify those that may need improvement. This information is essential for guiding our
resource allocation and strategic planning efforts.
SELECT
s.Store_ID, We’re selecting each Store_ID and Store_Name, then calculating the total sales in USD
1 SELECT s.Store_Name, (Total_Sales_USD) for each store by multiplying the number of units sold (sa.Units) by the product
SUM(sa.Units* p.Product_Price) AS price (p.Product_Price).
Total_Sales_USD
2 FROM FROM sales AS s The data comes from the sales table (sa), which contains details about the sales transactions.
WHERE
We filter the sales to include only those that occurred between January 1, 2022, and March
4 WHERE sa.Date >= '2022-01-01' AND sa.Date
31, 2022.
<= '2022-03-31'
GROUP BY The results are grouped by Store_ID and Store_Name, allowing us to calculate the total sales for
5 GROUP BY sa.Store_ID, s.Store_Name each store.
ORDER BY Finally, we sort the stores by Total_Sales_USD in descending order, so the stores with the highest
6 ORDER BY Total_Sales_USD DESC; sales appear at the top.