๐๐ฅ๐๐ ๐๐ ๐๐ฎ๐ฟ๐ฒ๐ฒ๐ฟ ๐ ๐ฎ๐๐๐ฒ๐ฟ๐ฐ๐น๐ฎ๐๐ ๐
Join this expert-led masterclass and discover how to become industry-ready for high-growth AI roles.
๐ Date: 24 September 2026
โฐ Time: 7:00 PMโ9:00 PM IST
๐ Mode: Online
๐ Certificate: Available to all attendees
Eligibility :- Graduates Passing In 2025 or earlier
๐ ๐ฅ๐ฒ๐ด๐ถ๐๐๐ฒ๐ฟ ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐ ๐
https://pdlink.in/4xAMeGW
โก Register now and take your first step towards a successful career in AI!
Join this expert-led masterclass and discover how to become industry-ready for high-growth AI roles.
๐ Date: 24 September 2026
โฐ Time: 7:00 PMโ9:00 PM IST
๐ Mode: Online
๐ Certificate: Available to all attendees
Eligibility :- Graduates Passing In 2025 or earlier
๐ ๐ฅ๐ฒ๐ด๐ถ๐๐๐ฒ๐ฟ ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐ ๐
https://pdlink.in/4xAMeGW
โก Register now and take your first step towards a successful career in AI!
โค1
๐ Complete Data Science Roadmap 2026
๐ Phase 3: SQL for Data Science
๐ Topic 1: SQL Basics โ SELECT
SQL is one of the most important skills for a Data Scientist because real-world data is often stored in relational databases.
Before using Python, Machine Learning, or advanced analytics, you will frequently need to:
Retrieve data
Filter data
Combine tables
Aggregate information
Create datasets for analysis
Answer business questions
We'll start from the foundation: SELECT.
๐น 1. What Is SQL?
SQL stands for:
Structured Query Language
It is used to communicate with relational databases.
For example, a company might store:
Customers
You can use SQL to retrieve specific information from this table.
๐น 2. What Is a Database?
A database is a structured system used to store and manage data.
A relational database stores information in tables.
For example:
Customers
Contains customer information.
Orders
Contains order information.
Products
Contains product information.
These tables can be related using common columns such as:
This becomes extremely important when we learn JOINs.
๐น 3. What Is a Table?
A table consists of:
Rows
Each row generally represents one record.
Example: One customer
Columns
Each column represents an attribute.
Example: customer_id, name, city, age
So:
Row โ Record
Column โ Attribute
๐น 4. Your First SQL Query
The basic SQL query is:
Let's break it down:
Specifies what data you want.
Means: Select all columns.
Specifies the table from which you want the data.
The table name.
So the query means:
Give me all columns from the customers table.
๐น 5. Selecting Specific Columns
You don't always need every column.
Suppose you only want:
Customer ID
Customer name
Use:
Result:
This is usually better than using
๐น 6. Selecting One Column
You can select a single column:
Result:
๐น 7. Selecting Multiple Columns
Separate column names using commas:
This returns only those three columns.
๐น 8. What Does * Mean?
The asterisk:
means: All columns.
Example:
If the table has 10 columns, the query returns all 10.
However, in production environments, it is often better to explicitly specify the columns you need.
Instead of:
prefer:
when those are the only fields required.
๐น 9. SQL Statements and Semicolon
SQL statements are commonly terminated with:
Example:
The semicolon indicates the end of the SQL statement in many SQL environments.
๐น 10. SQL Is Declarative
This is an important concept.
When you write:
๐ Phase 3: SQL for Data Science
๐ Topic 1: SQL Basics โ SELECT
SQL is one of the most important skills for a Data Scientist because real-world data is often stored in relational databases.
Before using Python, Machine Learning, or advanced analytics, you will frequently need to:
Retrieve data
Filter data
Combine tables
Aggregate information
Create datasets for analysis
Answer business questions
We'll start from the foundation: SELECT.
๐น 1. What Is SQL?
SQL stands for:
Structured Query Language
It is used to communicate with relational databases.
For example, a company might store:
Customers
customer_id | name | city | age
101 | Alice | Mumbai | 28
102 | Bob | Pune | 32
103 | Carol | Delhi | 25
You can use SQL to retrieve specific information from this table.
๐น 2. What Is a Database?
A database is a structured system used to store and manage data.
A relational database stores information in tables.
For example:
Customers
Contains customer information.
Orders
Contains order information.
Products
Contains product information.
These tables can be related using common columns such as:
customer_idThis becomes extremely important when we learn JOINs.
๐น 3. What Is a Table?
A table consists of:
Rows
Each row generally represents one record.
Example: One customer
Columns
Each column represents an attribute.
Example: customer_id, name, city, age
So:
Row โ Record
Column โ Attribute
๐น 4. Your First SQL Query
The basic SQL query is:
SELECT *
FROM customers;
Let's break it down:
SELECTSpecifies what data you want.
*Means: Select all columns.
FROMSpecifies the table from which you want the data.
customersThe table name.
So the query means:
Give me all columns from the customers table.
๐น 5. Selecting Specific Columns
You don't always need every column.
Suppose you only want:
Customer ID
Customer name
Use:
SELECT customer_id, name
FROM customers;
Result:
customer_id | name
101 | Alice
102 | Bob
103 | Carol
This is usually better than using
SELECT * when you only need a few columns.๐น 6. Selecting One Column
You can select a single column:
SELECT name
FROM customers;
Result:
name
Alice
Bob
Carol
๐น 7. Selecting Multiple Columns
Separate column names using commas:
SELECT name, city, age
FROM customers;
This returns only those three columns.
๐น 8. What Does * Mean?
The asterisk:
*means: All columns.
Example:
SELECT *
FROM customers;
If the table has 10 columns, the query returns all 10.
However, in production environments, it is often better to explicitly specify the columns you need.
Instead of:
SELECT *
FROM customers;
prefer:
SELECT customer_id, name, city
FROM customers;
when those are the only fields required.
๐น 9. SQL Statements and Semicolon
SQL statements are commonly terminated with:
;Example:
SELECT name
FROM customers;
The semicolon indicates the end of the SQL statement in many SQL environments.
๐น 10. SQL Is Declarative
This is an important concept.
When you write:
SELECT name
FROM customers;
โค1
you tell the database:
What data you want
You generally don't tell the database exactly how to retrieve it internally.
The database's query optimizer determines an efficient execution strategy.
This is one reason SQL is called a declarative language.
๐น 11. SQL Keywords
SQL uses keywords such as:
SELECT
FROM
WHERE
GROUP BY
ORDER BY
HAVING
JOIN
These keywords define the structure of the query.
For example:
Here:
SELECT โ What to retrieve
FROM โ Where to retrieve it from
๐น 12. SQL Case Sensitivity
SQL keywords are commonly written in uppercase:
SELECT
FROM
WHERE
This improves readability.
For example:
is easier to read than:
Most SQL database systems treat keywords as case-insensitive, although behavior regarding identifiers such as table and column names can vary by database system and configuration.
Recommended style:
Use:
UPPERCASE for SQL keywords
lowercase or snake_case for column/table names
๐น 13. Column Aliases
You can temporarily give a column a different name using
Example:
The result will display:
The original column name in the database is not changed.
The alias only changes how the result is displayed.
๐น 14. Aliases Without AS
In many SQL systems, you can also write:
However, using
๐น 15. Calculations in SELECT
SQL can perform calculations.
Suppose we have:
price
quantity
We can calculate total sales:
This creates a calculated column:
This ability becomes extremely useful in Data Analytics.
๐น 16. Using SELECT with Expressions
You can perform various calculations.
Example:
If monthly salary is:
โน50,000
then:
The original database isn't modified.
The calculation is performed when the query runs.
๐น 17. Selecting Constants
SQL can also return constant values.
Example:
Result:
You can also use numbers:
Result:
This becomes useful when constructing analytical datasets.
๐น 18. DISTINCT
DISTINCT is part of the roadmap and we'll study it properly later.
For now, understand its basic purpose:
It returns unique values.
Suppose:
city
Pune
Mumbai
Pune
Delhi
Mumbai
Query:
Result:
Duplicate values are removed from the result.
๐น 19. SELECT DISTINCT on Multiple Columns
You can use multiple columns:
Important:
DISTINCT applies to the combination of selected columns.
So if two rows have the same city but different departments, they are considered different combinations.
๐น 20. SQL Query Example
Imagine an orders table:
What data you want
You generally don't tell the database exactly how to retrieve it internally.
The database's query optimizer determines an efficient execution strategy.
This is one reason SQL is called a declarative language.
๐น 11. SQL Keywords
SQL uses keywords such as:
SELECT
FROM
WHERE
GROUP BY
ORDER BY
HAVING
JOIN
These keywords define the structure of the query.
For example:
SELECT name
FROM customers;
Here:
SELECT โ What to retrieve
FROM โ Where to retrieve it from
๐น 12. SQL Case Sensitivity
SQL keywords are commonly written in uppercase:
SELECT
FROM
WHERE
This improves readability.
For example:
SELECT customer_id, name
FROM customers;
is easier to read than:
select customer_id,name from customers;
Most SQL database systems treat keywords as case-insensitive, although behavior regarding identifiers such as table and column names can vary by database system and configuration.
Recommended style:
Use:
UPPERCASE for SQL keywords
lowercase or snake_case for column/table names
๐น 13. Column Aliases
You can temporarily give a column a different name using
AS.Example:
SELECT
name AS customer_name
FROM customers;
The result will display:
customer_name
Alice
Bob
Carol
The original column name in the database is not changed.
The alias only changes how the result is displayed.
๐น 14. Aliases Without AS
In many SQL systems, you can also write:
SELECT
name customer_name
FROM customers;
However, using
AS is generally clearer:SELECT
name AS customer_name
FROM customers;
๐น 15. Calculations in SELECT
SQL can perform calculations.
Suppose we have:
price
quantity
We can calculate total sales:
SELECT
price,
quantity,
price * quantity AS total_amount
FROM orders;
This creates a calculated column:
total_amount = price ร quantityThis ability becomes extremely useful in Data Analytics.
๐น 16. Using SELECT with Expressions
You can perform various calculations.
Example:
SELECT
salary,
salary * 12 AS annual_salary
FROM employees;
If monthly salary is:
โน50,000
then:
annual_salary = โน600,000The original database isn't modified.
The calculation is performed when the query runs.
๐น 17. Selecting Constants
SQL can also return constant values.
Example:
SELECT
'Data Science' AS course;
Result:
course
Data Science
You can also use numbers:
SELECT
2026 AS year;
Result:
year
2026
This becomes useful when constructing analytical datasets.
๐น 18. DISTINCT
DISTINCT is part of the roadmap and we'll study it properly later.
For now, understand its basic purpose:
It returns unique values.
Suppose:
city
Pune
Mumbai
Pune
Delhi
Mumbai
Query:
SELECT DISTINCT city
FROM customers;
Result:
Pune
Mumbai
Delhi
Duplicate values are removed from the result.
๐น 19. SELECT DISTINCT on Multiple Columns
You can use multiple columns:
SELECT DISTINCT city, department
FROM employees;
Important:
DISTINCT applies to the combination of selected columns.
So if two rows have the same city but different departments, they are considered different combinations.
๐น 20. SQL Query Example
Imagine an orders table:
โค1
order_id | customer_id | product | price
1 | 101 | Laptop | 60000
2 | 102 | Phone | 30000
3 | 101 | Mouse | 1000
To retrieve order details:
SELECT
order_id,
customer_id,
product,
price
FROM orders;
To calculate price after adding a hypothetical 10% increase:
SELECT
product,
price,
price * 1.10 AS increased_price
FROM orders;
๐น 21. SELECT in Real-World Data Science
SQL is often the first step in a Data Science workflow.
For example:
Business Question
"Give me all customer transactions from the sales database."
You might start with:
SELECT
customer_id,
order_date,
product_id,
amount
FROM transactions;
Then later:
WHERE โ Filter data
GROUP BY โ Aggregate data
JOIN โ Combine tables
ORDER BY โ Sort results
Window Functions โ Advanced analysis
Eventually, you may load the SQL result into Pandas:
import pandas as pd
df = pd.read_sql(query, connection)
So SQL and Python often work together.
๐น 22. Common Beginner Mistakes
โ Mistake 1: Forgetting the FROM clause
Incorrect:
SELECT name;when you intend to retrieve a column from a table.
Correct:
SELECT name
FROM customers;
โ Mistake 2: Using commas incorrectly
Correct:
SELECT name, city, age
FROM customers;
โ Mistake 3: Confusing column names and values
A column:
cityis different from a text value:
'Pune'We'll explore this more when we learn WHERE.
โ Mistake 4: Using SELECT * everywhere
SELECT * is useful while learning and exploring, but for production queries, selecting only the required columns can be more efficient and clearer.๐น 23. Interview Questions
๐ก What does SELECT do?
SELECT specifies the columns or expressions that should appear in the query result.
๐ก What does SELECT * mean?
It selects all columns from the specified table.
๐ก What is an alias?
An alias gives a temporary name to a column or expression in the query result.
๐ก What does DISTINCT do?
It removes duplicate rows from the selected result.
๐ฏ Practice Questions
Q1. Write a query to select all columns from a table called employees.
Q2. Write a query to select only employee_id and salary from employees.
Q3. Write a query to display salary as monthly_salary.
Q4. Write a query to calculate price * quantity as total_amount from an orders table.
Q5. Write a query to return unique values from the department column of an employees table.
๐ฏ Key Takeaways
โ SQL is used to communicate with relational databases.
โ SELECT specifies what you want to retrieve.
โ FROM specifies the table.
โ
* means all columns.โ You can select one or multiple columns.
โ AS creates a temporary alias.
โ SQL can perform calculations.
โ DISTINCT returns unique results.
โ SQL is one of the most important tools for extracting data before analysis and Machine Learning.
๐งญ Double Tap โค๏ธ For More
โค5
๐ ๐ฆ๐๐ฎ๐ป๐ณ๐ผ๐ฟ๐ฑ ๐จ๐ป๐ถ๐๐ฒ๐ฟ๐๐ถ๐๐ ๐๐ฅ๐๐ ๐ข๐ป๐น๐ถ๐ป๐ฒ ๐๐ผ๐๐ฟ๐๐ฒ๐! ๐
Explore free online learning opportunities from Stanford University across technology, business and more!
๐ป Tech & Programming
๐ค Artificial Intelligence & Data Science
๐ผ Business & Entrepreneurship
๐ก Leadership & Innovation
๐ ๐๐ ๐ฝ๐น๐ผ๐ฟ๐ฒ ๐๐ต๐ฒ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐
https://pdlink.in/4hlnZGw
๐ฏ Great for students, freshers and working professionals looking to expand their knowledge.
Explore free online learning opportunities from Stanford University across technology, business and more!
๐ป Tech & Programming
๐ค Artificial Intelligence & Data Science
๐ผ Business & Entrepreneurship
๐ก Leadership & Innovation
๐ ๐๐ ๐ฝ๐น๐ผ๐ฟ๐ฒ ๐๐ต๐ฒ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐
https://pdlink.in/4hlnZGw
๐ฏ Great for students, freshers and working professionals looking to expand their knowledge.
โค6
๐ ๐ง๐ผ๐ฝ ๐ณ ๐๐ฅ๐๐ ๐ ๐ถ๐ฐ๐ฟ๐ผ๐๐ผ๐ณ๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ผ ๐๐ฒ๐ฎ๐ฟ๐ป ๐๐ฎ๐๐ฎ ๐๐ป๐ฎ๐น๐๐๐ถ๐ฐ๐! ๐
Want to start a career in Data Analytics?
Explore these 7 free Microsoft-backed learning resources covering Power BI, Excel, SQL and data fundamentals
๐ ๐๐ฐ๐ฐ๐ฒ๐๐ ๐๐ต๐ฒ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐
https://pdlink.in/3Tm2D3Z
๐ก Ideal for students, freshers and professionals who want to build practical data skills.
Want to start a career in Data Analytics?
Explore these 7 free Microsoft-backed learning resources covering Power BI, Excel, SQL and data fundamentals
๐ ๐๐ฐ๐ฐ๐ฒ๐๐ ๐๐ต๐ฒ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐
https://pdlink.in/3Tm2D3Z
๐ก Ideal for students, freshers and professionals who want to build practical data skills.
โค2
Soft skills questions will be part of your next data job interview!
Here is what you should prepare for:
1. ๐๐ผ๐บ๐บ๐๐ป๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป: Be ready to discuss how you explain complex data insights to non-technical stakeholders.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โHow do you ensure that your data insights are understood and get used by non-technical stakeholders?โ
2. ๐ง๐ฒ๐ฎ๐บ ๐๐ผ๐น๐น๐ฎ๐ฏ๐ผ๐ฟ๐ฎ๐๐ถ๐ผ๐ป: Show your ability to work well with others.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โCan you talk about a time when you had to manage a conflict within a team? How did you resolve it?โ
3. ๐ฃ๐ฟ๐ผ๐ฏ๐น๐ฒ๐บ-๐ฆ๐ผ๐น๐๐ถ๐ป๐ด: Highlight your critical thinking and problem-solving skills.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โDescribe a situation where you had to make a quick decision based on incomplete data. What was the outcome?โ
4. ๐๐ฑ๐ฎ๐ฝ๐๐ฎ๐ฏ๐ถ๐น๐ถ๐๐: Demonstrate your flexibility and openness to change.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โHow do you handle sudden changes in project priorities or scope?โ
5. ๐ง๐ถ๐บ๐ฒ ๐ ๐ฎ๐ป๐ฎ๐ด๐ฒ๐บ๐ฒ๐ป๐: Prove your ability to manage multiple tasks and deadlines.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โTell me about a time when you were under tight deadlines. How did you manage to meet them?โ
6. ๐๐บ๐ฝ๐ฎ๐๐ต๐ ๐ฎ๐ป๐ฑ ๐จ๐ป๐ฑ๐ฒ๐ฟ๐๐๐ฎ๐ป๐ฑ๐ถ๐ป๐ด: Show your ability to understand stakeholder needs.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โHow do you approach understanding the needs of different stakeholders when starting a new project?โ
Structure your answers using the STAR method (Situation, Task, Action, Result). This helps you provide clear and concise responses that highlight your skills.
By preparing for these soft skills questions, youโll demonstrate that youโre not just technically fit, but also a well-rounded professional ready to make an impact on the business.
You can find useful tips to improve your soft skills here: ๐ https://t.me/englishlearnerspro/
Here is what you should prepare for:
1. ๐๐ผ๐บ๐บ๐๐ป๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป: Be ready to discuss how you explain complex data insights to non-technical stakeholders.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โHow do you ensure that your data insights are understood and get used by non-technical stakeholders?โ
2. ๐ง๐ฒ๐ฎ๐บ ๐๐ผ๐น๐น๐ฎ๐ฏ๐ผ๐ฟ๐ฎ๐๐ถ๐ผ๐ป: Show your ability to work well with others.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โCan you talk about a time when you had to manage a conflict within a team? How did you resolve it?โ
3. ๐ฃ๐ฟ๐ผ๐ฏ๐น๐ฒ๐บ-๐ฆ๐ผ๐น๐๐ถ๐ป๐ด: Highlight your critical thinking and problem-solving skills.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โDescribe a situation where you had to make a quick decision based on incomplete data. What was the outcome?โ
4. ๐๐ฑ๐ฎ๐ฝ๐๐ฎ๐ฏ๐ถ๐น๐ถ๐๐: Demonstrate your flexibility and openness to change.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โHow do you handle sudden changes in project priorities or scope?โ
5. ๐ง๐ถ๐บ๐ฒ ๐ ๐ฎ๐ป๐ฎ๐ด๐ฒ๐บ๐ฒ๐ป๐: Prove your ability to manage multiple tasks and deadlines.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โTell me about a time when you were under tight deadlines. How did you manage to meet them?โ
6. ๐๐บ๐ฝ๐ฎ๐๐ต๐ ๐ฎ๐ป๐ฑ ๐จ๐ป๐ฑ๐ฒ๐ฟ๐๐๐ฎ๐ป๐ฑ๐ถ๐ป๐ด: Show your ability to understand stakeholder needs.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ ๐ฒ๐ถ๐ฆ๐ด๐ต๐ช๐ฐ๐ฏ:
โHow do you approach understanding the needs of different stakeholders when starting a new project?โ
Structure your answers using the STAR method (Situation, Task, Action, Result). This helps you provide clear and concise responses that highlight your skills.
By preparing for these soft skills questions, youโll demonstrate that youโre not just technically fit, but also a well-rounded professional ready to make an impact on the business.
You can find useful tips to improve your soft skills here: ๐ https://t.me/englishlearnerspro/
โค8
๐ Data Science Roadmap 2026
**
๐ Phase 3: SQL for Data Science**
๐ Topic 2: SQL Basics โ WHERE
After learning SELECT, the next essential SQL concept is WHERE.
In real-world Data Science, databases can contain millions or billions of records. You usually don't want to retrieve everything.
You want to answer questions such as:
Which customers are from Mumbai?
Which orders are above โน10,000?
Which employees joined after 2023?
Which transactions were successful?
Which products belong to a particular category?
The WHERE clause allows you to filter rows based on conditions.
๐น 1. What Is WHERE?
WHERE is used to filter records based on a specified condition.
Basic syntax:
Example:
This returns only customers whose city is Mumbai.
๐น 2. WHERE with Text Values
Text values are generally written inside single quotes.
Example:
This retrieves customers from Pune.
Another example:
๐น 3. WHERE with Numbers
For numeric values, quotes are generally not required.
Example:
This returns customers older than 30.
Another example:
This returns orders where the amount is greater than 10,000.
๐น 4. Comparison Operators
The most commonly used comparison operators are:
Operator Meaning
= Equal to
<> Not equal to
!= Not equal to
Example:
This returns employees whose salary is at least 50,000.
๐น 5. Equal To =
The = operator checks whether two values are equal.
Only records where city equals Delhi are returned.
๐น 6. Not Equal <>
You can retrieve records that don't match a value.
This returns customers whose city isn't Delhi.
You may also see:
Both are commonly supported, although <> is the standard SQL operator.
๐น 7. Greater Than >
Example:
Returns orders above 50,000.
๐น 8. Less Than <
Example:
Returns products priced below 1,000.
๐น 9. Greater Than or Equal To >=
Example:
This includes employees with exactly 5 years as well as those with more than 5 years.
๐น 10. Less Than or Equal To <=
Example:
This includes products priced exactly at 500.
๐น 11. WHERE with Multiple Conditions
Real-world queries often require more than one condition.
For this, SQL provides logical operators:
โข AND
โข OR
โข NOT
๐น 12. AND
AND means all conditions must be true.
Example:
This returns customers who:
1.
Are from Pune
2.
Are older than 30
Both conditions must be satisfied.
๐น 13. OR
OR means at least one condition must be true.
Example:
**
๐ Phase 3: SQL for Data Science**
๐ Topic 2: SQL Basics โ WHERE
After learning SELECT, the next essential SQL concept is WHERE.
In real-world Data Science, databases can contain millions or billions of records. You usually don't want to retrieve everything.
You want to answer questions such as:
Which customers are from Mumbai?
Which orders are above โน10,000?
Which employees joined after 2023?
Which transactions were successful?
Which products belong to a particular category?
The WHERE clause allows you to filter rows based on conditions.
๐น 1. What Is WHERE?
WHERE is used to filter records based on a specified condition.
Basic syntax:
SELECT column1, column2
FROM table_name
WHERE condition;
Example:
SELECT *
FROM customers
WHERE city = 'Mumbai';
This returns only customers whose city is Mumbai.
๐น 2. WHERE with Text Values
Text values are generally written inside single quotes.
Example:
SELECT customer_id, name
FROM customers
WHERE city = 'Pune';
This retrieves customers from Pune.
Another example:
SELECT *
FROM employees
WHERE department = 'Finance';
๐น 3. WHERE with Numbers
For numeric values, quotes are generally not required.
Example:
SELECT *
FROM customers
WHERE age > 30;
This returns customers older than 30.
Another example:
SELECT *
FROM orders
WHERE amount > 10000;
This returns orders where the amount is greater than 10,000.
๐น 4. Comparison Operators
The most commonly used comparison operators are:
Operator Meaning
= Equal to
<> Not equal to
!= Not equal to
Greater than
< Less than
= Greater than or equal to
<= Less than or equal to
Example:
SELECT *
FROM employees
WHERE salary >= 50000;
This returns employees whose salary is at least 50,000.
๐น 5. Equal To =
The = operator checks whether two values are equal.
SELECT *
FROM customers
WHERE city = 'Delhi';
Only records where city equals Delhi are returned.
๐น 6. Not Equal <>
You can retrieve records that don't match a value.
SELECT *
FROM customers
WHERE city <> 'Delhi';
This returns customers whose city isn't Delhi.
You may also see:
WHERE city != 'Delhi'
Both are commonly supported, although <> is the standard SQL operator.
๐น 7. Greater Than >
Example:
SELECT *
FROM orders
WHERE amount > 50000;
Returns orders above 50,000.
๐น 8. Less Than <
Example:
SELECT *
FROM products
WHERE price < 1000;
Returns products priced below 1,000.
๐น 9. Greater Than or Equal To >=
Example:
SELECT *
FROM employees
WHERE experience >= 5;
This includes employees with exactly 5 years as well as those with more than 5 years.
๐น 10. Less Than or Equal To <=
Example:
SELECT *
FROM products
WHERE price <= 500;
This includes products priced exactly at 500.
๐น 11. WHERE with Multiple Conditions
Real-world queries often require more than one condition.
For this, SQL provides logical operators:
โข AND
โข OR
โข NOT
๐น 12. AND
AND means all conditions must be true.
Example:
SELECT *
FROM customers
WHERE city = 'Pune'
AND age > 30;
This returns customers who:
1.
Are from Pune
2.
Are older than 30
Both conditions must be satisfied.
๐น 13. OR
OR means at least one condition must be true.
Example:
SELECT *
FROM customers
WHERE city = 'Pune'
OR city = 'Mumbai';
This returns customers from either Pune or Mumbai.
๐น 14. AND vs OR
Consider:
WHERE age > 30
AND city = 'Pune'
A customer must satisfy both conditions.
But:
WHERE age > 30
OR city = 'Pune'
A customer only needs to satisfy one or both conditions.
This difference is extremely important.
๐น 15. NOT
NOT reverses a condition.
Example:
SELECT *
FROM customers
WHERE NOT city = 'Pune';
This returns customers who aren't from Pune.
You can also commonly write:
SELECT *
FROM customers
WHERE city <> 'Pune';
๐น 16. Combining AND and OR
You can combine multiple logical operators.
Example:
SELECT *
FROM employees
WHERE department = 'Finance'
AND salary > 60000;
Another example:
SELECT *
FROM employees
WHERE department = 'Finance'
OR department = 'Analytics'
AND salary > 60000;
When conditions become complex, use parentheses to make your intended logic explicit.
For example:
SELECT *
FROM employees
WHERE
(department = 'Finance' OR department = 'Analytics')
AND salary > 60000;
This means:
Employees from Finance or Analytics who earn more than 60,000.
๐น 17. Why Parentheses Matter
Consider:
WHERE city = 'Pune'
OR city = 'Mumbai'
AND age > 30
SQL's logical evaluation rules can make this behave differently from what a beginner might expect.
A safer and clearer version is:
WHERE
(city = 'Pune' OR city = 'Mumbai')
AND age > 30;
This clearly communicates the intended logic.
Best practice:
Use parentheses whenever combining AND and OR in a complex condition.
๐น 18. WHERE with Dates
You can also filter dates.
Example:
SELECT *
FROM orders
WHERE order_date >= '2026-01-01';
This retrieves orders on or after January 1, 2026.
Another example:
SELECT *
FROM orders
WHERE order_date < '2026-07-01';
This retrieves orders before July 1, 2026.
Date syntax can vary slightly across database systems, so always consider the SQL dialect you're using.
๐น 19. Filtering a Date Range
Suppose you want orders during a particular period.
You can use:
SELECT *
FROM orders
WHERE order_date >= '2026-01-01'
AND order_date < '2026-04-01';
This retrieves orders from January through March.
Using a half-open range like this is particularly useful when working with timestamps because it avoids accidentally excluding records with time components.
๐น 20. BETWEEN
SQL provides BETWEEN for range filtering.
Example:
SELECT *
FROM products
WHERE price BETWEEN 1000 AND 5000;
BETWEEN is inclusive of both boundaries in standard SQL.
So this includes:
1000
and:
5000
as well as values between them.
๐น 21. BETWEEN with Dates
Example:
SELECT *
FROM orders
WHERE order_date BETWEEN '2026-01-01' AND '2026-01-31';
For a date-only column, this can be useful.
However, if order_date contains timestamps, using:
order_date >= '2026-01-01'
AND order_date < '2026-02-01'
is often safer because it includes the entire final day regardless of the timestamp.
๐น 22. IN Operator
Suppose you want customers from:
Pune
Mumbai
Delhi
You could write:
SELECT *
FROM customers
WHERE city = 'Pune'
OR city = 'Mumbai'
OR city = 'Delhi';
But IN makes this much cleaner:
IN checks whether a value belongs to a specified list.
๐น 23. NOT IN
You can also exclude multiple values.
This returns customers whose city isn't Pune or Mumbai.
๐น 24. LIKE
LIKE is used for pattern matching.
Suppose we want names beginning with A.
Here:
% โ Any sequence of characters
So this could match:
Alice
Amit
Ananya
๐น 25. LIKE with %
Example:
This searches for names containing the sequence an.
The exact behavior can depend on database collation and case-sensitivity settings.
๐น 26. LIKE with _
The underscore _ generally represents exactly one character.
Example:
This could match:
A11
AB1
AX1
But not:
A123
A1
because _ represents one character.
๐น 27. NULL Values
One of the most important concepts in SQL filtering is NULL.
NULL generally means:
It does not mean:
Zero
Empty string
False
For example:
customer_id name phone
101 Alice 9999999999
102 Bob NULL
Bob's phone number is missing or unknown.
๐น 28. Checking for NULL
You should not normally write:
Instead, use:
To find records where the value exists:
This is extremely important in Data Analytics.
๐น 29. WHERE and NULL Logic
Suppose:
What happens when salary is NULL?
The condition isn't considered true.
The row won't be returned.
SQL uses three-valued logic involving:
TRUE
FALSE
UNKNOWN
This is one reason NULL handling requires special attention.
๐น 30. WHERE with SELECT
WHERE works together with SELECT.
Example:
The query:
1.
Retrieves selected columns
2.
From the customers table
3.
Keeps only rows satisfying the condition
๐น 31. WHERE in Real-World Data Science
Imagine a transaction database containing millions of records.
A Data Scientist needs:
A query might look like:
This is much more efficient for analysis than extracting the entire table and filtering everything later in Python.
๐น 32. WHERE Before Python
A common Data Science workflow is:
Database โ SQL โ Filter/Transform โ Python โ Analysis โ Model
For example:
Then load the result into Pandas:
SQL handles the database-side filtering, while Python can then handle deeper analysis.
๐น 33. Common Mistakes
โ Mistake 1: Using = with NULL
Incorrect:
Correct:
SELECT *
FROM customers
WHERE city IN ('Pune', 'Mumbai', 'Delhi');
IN checks whether a value belongs to a specified list.
๐น 23. NOT IN
You can also exclude multiple values.
SELECT *
FROM customers
WHERE city NOT IN ('Pune', 'Mumbai');
This returns customers whose city isn't Pune or Mumbai.
๐น 24. LIKE
LIKE is used for pattern matching.
Suppose we want names beginning with A.
SELECT *
FROM customers
WHERE name LIKE 'A%';
Here:
% โ Any sequence of characters
So this could match:
Alice
Amit
Ananya
๐น 25. LIKE with %
Example:
SELECT *
FROM customers
WHERE name LIKE '%an%';
This searches for names containing the sequence an.
The exact behavior can depend on database collation and case-sensitivity settings.
๐น 26. LIKE with _
The underscore _ generally represents exactly one character.
Example:
SELECT *
FROM products
WHERE product_code LIKE 'A_1';
This could match:
A11
AB1
AX1
But not:
A123
A1
because _ represents one character.
๐น 27. NULL Values
One of the most important concepts in SQL filtering is NULL.
NULL generally means:
Missing, unknown, or unavailable value.
It does not mean:
Zero
Empty string
False
For example:
customer_id name phone
101 Alice 9999999999
102 Bob NULL
Bob's phone number is missing or unknown.
๐น 28. Checking for NULL
You should not normally write:
WHERE phone = NULL
Instead, use:
SELECT *
FROM customers
WHERE phone IS NULL;
To find records where the value exists:
SELECT *
FROM customers
WHERE phone IS NOT NULL;
This is extremely important in Data Analytics.
๐น 29. WHERE and NULL Logic
Suppose:
WHERE salary > 50000
What happens when salary is NULL?
The condition isn't considered true.
The row won't be returned.
SQL uses three-valued logic involving:
TRUE
FALSE
UNKNOWN
This is one reason NULL handling requires special attention.
๐น 30. WHERE with SELECT
WHERE works together with SELECT.
Example:
SELECT
customer_id,
name,
city
FROM customers
WHERE city = 'Pune';
The query:
1.
Retrieves selected columns
2.
From the customers table
3.
Keeps only rows satisfying the condition
๐น 31. WHERE in Real-World Data Science
Imagine a transaction database containing millions of records.
A Data Scientist needs:
Successful transactions above โน10,000 from January 2026 onward.
A query might look like:
SELECT
transaction_id,
customer_id,
transaction_date,
amount
FROM transactions
WHERE status = 'Success'
AND amount > 10000
AND transaction_date >= '2026-01-01';
This is much more efficient for analysis than extracting the entire table and filtering everything later in Python.
๐น 32. WHERE Before Python
A common Data Science workflow is:
Database โ SQL โ Filter/Transform โ Python โ Analysis โ Model
For example:
SELECT
customer_id,
amount,
transaction_date
FROM transactions
WHERE status = 'Success';
Then load the result into Pandas:
import pandas as pd
df = pd.read_sql(query, connection)
SQL handles the database-side filtering, while Python can then handle deeper analysis.
๐น 33. Common Mistakes
โ Mistake 1: Using = with NULL
Incorrect:
WHERE phone = NULL;
Correct:
WHERE phone IS NULL;
โ Mistake 2: Forgetting quotes around text
Incorrect:
Correct:
โ Mistake 3: Using AND when you mean OR
Incorrect if you want either city:
A single city value cannot normally be both at the same time.
Correct:
Or:
โ Mistake 4: Forgetting parentheses
For complex conditions, use parentheses:
โ Mistake 5: Assuming BETWEEN excludes the boundaries
BETWEEN is generally inclusive.
๐น 34. Interview Questions
๐ก What is the purpose of WHERE?
WHERE filters rows based on a condition.
๐ก What is the difference between WHERE and SELECT?
SELECT โ Determines what columns/expressions appear in the result.
WHERE โ Determines which rows are included.
๐ก How do you check for NULL?
Use:
IS NULL
or:
IS NOT NULL
๐ก What is the difference between IN and OR?
IN provides a concise way to test whether a value matches any value in a list.
๐ก Is BETWEEN inclusive?
Yes, BETWEEN generally includes both boundary values.
๐ฏ Practice Questions
Q1. Write a query to retrieve employees whose salary is greater than 50,000.
Q2. Write a query to retrieve customers from Pune or Mumbai.
Q3. Write a query to retrieve products priced between 1,000 and 5,000.
Q4. Write a query to retrieve customers whose phone number is missing.
Q5. Write a query to retrieve orders where the status is Success and the amount is greater than 10,000.
๐ฏ Key Takeaways
โ WHERE is used to filter rows.
โ = checks equality.
โ <> and != can be used for not equal.
โ AND requires all specified conditions to be true.
โ OR requires at least one condition to be true.
โ IN is useful for matching multiple values.
โ BETWEEN is useful for ranges and is generally inclusive.
โ LIKE is used for pattern matching.
โ % represents a sequence of characters.
โ _ represents one character.
โ Use IS NULL and IS NOT NULL for NULL values.
โ Parentheses make complex AND/OR logic clearer and safer.
๐งญ Double Tap โค๏ธ For More
Incorrect:
WHERE city = Pune;
Correct:
WHERE city = 'Pune';
โ Mistake 3: Using AND when you mean OR
Incorrect if you want either city:
WHERE city = 'Pune'
AND city = 'Mumbai';
A single city value cannot normally be both at the same time.
Correct:
WHERE city = 'Pune'
OR city = 'Mumbai';
Or:
WHERE city IN ('Pune', 'Mumbai');โ Mistake 4: Forgetting parentheses
For complex conditions, use parentheses:
WHERE
(city = 'Pune' OR city = 'Mumbai')
AND age > 30;
โ Mistake 5: Assuming BETWEEN excludes the boundaries
BETWEEN is generally inclusive.
๐น 34. Interview Questions
๐ก What is the purpose of WHERE?
WHERE filters rows based on a condition.
๐ก What is the difference between WHERE and SELECT?
SELECT โ Determines what columns/expressions appear in the result.
WHERE โ Determines which rows are included.
๐ก How do you check for NULL?
Use:
IS NULL
or:
IS NOT NULL
๐ก What is the difference between IN and OR?
IN provides a concise way to test whether a value matches any value in a list.
๐ก Is BETWEEN inclusive?
Yes, BETWEEN generally includes both boundary values.
๐ฏ Practice Questions
Q1. Write a query to retrieve employees whose salary is greater than 50,000.
Q2. Write a query to retrieve customers from Pune or Mumbai.
Q3. Write a query to retrieve products priced between 1,000 and 5,000.
Q4. Write a query to retrieve customers whose phone number is missing.
Q5. Write a query to retrieve orders where the status is Success and the amount is greater than 10,000.
๐ฏ Key Takeaways
โ WHERE is used to filter rows.
โ = checks equality.
โ <> and != can be used for not equal.
โ AND requires all specified conditions to be true.
โ OR requires at least one condition to be true.
โ IN is useful for matching multiple values.
โ BETWEEN is useful for ranges and is generally inclusive.
โ LIKE is used for pattern matching.
โ % represents a sequence of characters.
โ _ represents one character.
โ Use IS NULL and IS NOT NULL for NULL values.
โ Parentheses make complex AND/OR logic clearer and safer.
๐งญ Double Tap โค๏ธ For More
โค3