1. Handling Missing Values
- Kaggle Tutorial: [Handling Missing Values](https://www.kaggle.com/learn/data-cleaning)
- YouTube Video: ["Dealing with Missing Data in Python"](https://www.youtube.com/watch?v=wvsE8jm1GzE) by Data School
- Blog Post: [Complete Guide to Handling Missing Data in Python](https://towardsdatascience.com/complete-guide-to-handling-missing-data-in-python-95c1221fba0e)
---
2. Data Normalization and Standardization
- Blog Post: [Normalization vs. Standardization Explained](https://machinelearningmastery.com/normalize-standardize-machine-learning-data-python/)
- Interactive Course: [Feature Scaling and Normalization (DataCamp)](https://www.datacamp.com/)
- YouTube Video: ["Feature Scaling in Machine Learning"](https://www.youtube.com/watch?v=UvK0B5JZpM8) by StatQuest
---
3. Removing Duplicates
- Official Pandas Documentation: [Pandas drop_duplicates()](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop_duplicates.html)
- Video: ["Removing Duplicates in Python"](https://www.youtube.com/watch?v=QHRrl4Il2Og) by Corey Schafer
- Blog Post: [How to Remove Duplicates Using Python](https://realpython.com/python-data-cleaning-numpy-pandas/)
---
4. Handling Outliers
- Blog Post: [5 Methods to Deal with Outliers in Data](https://towardsdatascience.com/handling-outliers-in-your-data-7cde6b4d76bb)
- Video: ["Identifying and Handling Outliers in Python"](https://www.youtube.com/watch?v=TN-xVNUcDk8) by Krish Naik
- Jupyter Notebook Example: [Outlier Detection with Python](https://github.com/datascience-projects)
---
5. Merging and Joining Datasets
- Pandas Documentation: [Merging, Joining, and Concatenating](https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html)
- Video: ["Pandas Merging and Joining"](https://www.youtube.com/watch?v=g7n1MKo7WgQ) by Corey Schafer
- Interactive Course: [Data Manipulation with Pandas (DataCamp)](https://www.datacamp.com/)
---
6. Identifying and Correcting Data Inconsistencies
- Blog Post: [Python for Data Cleaning](https://towardsdatascience.com/python-for-data-cleaning-a-step-by-step-guide-to-deal-with-data-inconsistencies-c08f06fca8c8)
- Video Tutorial: ["Python for Data Cleaning"](https://www.youtube.com/watch?v=B_L0v1xRb6E)
- Project-Based Learning: [Data Cleaning in Python Mini-Projects](https://github.com/topics/data-cleaning)
---
๐ก Pro Tip: Practice real-world data cleaning tasks using open datasets on platforms like:
- [Kaggle Datasets](https://www.kaggle.com/datasets)
- [Data World](https://data.world/)
- [UCI Machine Learning Repository](https://archive.ics.uci.edu/ml/index.php)
- Kaggle Tutorial: [Handling Missing Values](https://www.kaggle.com/learn/data-cleaning)
- YouTube Video: ["Dealing with Missing Data in Python"](https://www.youtube.com/watch?v=wvsE8jm1GzE) by Data School
- Blog Post: [Complete Guide to Handling Missing Data in Python](https://towardsdatascience.com/complete-guide-to-handling-missing-data-in-python-95c1221fba0e)
---
2. Data Normalization and Standardization
- Blog Post: [Normalization vs. Standardization Explained](https://machinelearningmastery.com/normalize-standardize-machine-learning-data-python/)
- Interactive Course: [Feature Scaling and Normalization (DataCamp)](https://www.datacamp.com/)
- YouTube Video: ["Feature Scaling in Machine Learning"](https://www.youtube.com/watch?v=UvK0B5JZpM8) by StatQuest
---
3. Removing Duplicates
- Official Pandas Documentation: [Pandas drop_duplicates()](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop_duplicates.html)
- Video: ["Removing Duplicates in Python"](https://www.youtube.com/watch?v=QHRrl4Il2Og) by Corey Schafer
- Blog Post: [How to Remove Duplicates Using Python](https://realpython.com/python-data-cleaning-numpy-pandas/)
---
4. Handling Outliers
- Blog Post: [5 Methods to Deal with Outliers in Data](https://towardsdatascience.com/handling-outliers-in-your-data-7cde6b4d76bb)
- Video: ["Identifying and Handling Outliers in Python"](https://www.youtube.com/watch?v=TN-xVNUcDk8) by Krish Naik
- Jupyter Notebook Example: [Outlier Detection with Python](https://github.com/datascience-projects)
---
5. Merging and Joining Datasets
- Pandas Documentation: [Merging, Joining, and Concatenating](https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html)
- Video: ["Pandas Merging and Joining"](https://www.youtube.com/watch?v=g7n1MKo7WgQ) by Corey Schafer
- Interactive Course: [Data Manipulation with Pandas (DataCamp)](https://www.datacamp.com/)
---
6. Identifying and Correcting Data Inconsistencies
- Blog Post: [Python for Data Cleaning](https://towardsdatascience.com/python-for-data-cleaning-a-step-by-step-guide-to-deal-with-data-inconsistencies-c08f06fca8c8)
- Video Tutorial: ["Python for Data Cleaning"](https://www.youtube.com/watch?v=B_L0v1xRb6E)
- Project-Based Learning: [Data Cleaning in Python Mini-Projects](https://github.com/topics/data-cleaning)
---
๐ก Pro Tip: Practice real-world data cleaning tasks using open datasets on platforms like:
- [Kaggle Datasets](https://www.kaggle.com/datasets)
- [Data World](https://data.world/)
- [UCI Machine Learning Repository](https://archive.ics.uci.edu/ml/index.php)
Kaggle
Learn Data Cleaning Tutorials
Master efficient workflows for cleaning real-world, messy data.
โค3๐3
๐๐๐ฏ๐จ๐ฅ๐ฎ๐ญ - ๐๐จ๐ซ๐ค ๐
๐ซ๐จ๐ฆ ๐๐จ๐ฆ๐
Position: Business Analyst
Qualification: Bachelor's/ Master's Degree
Salary: 5 - 8 LPA (Expected)
Experienc๏ปฟe: Freshers/ Experienced
Location: Work From Home (Remote)
๐Apply Now: https://www.revolut.com/careers/position/75445311-c0e0-4b6d-90d4-d4a23226831c/
Position: Business Analyst
Qualification: Bachelor's/ Master's Degree
Salary: 5 - 8 LPA (Expected)
Experienc๏ปฟe: Freshers/ Experienced
Location: Work From Home (Remote)
๐Apply Now: https://www.revolut.com/careers/position/75445311-c0e0-4b6d-90d4-d4a23226831c/
Revolut
Business Analyst (Regulatory Reporting Functional) | Revolut United Kingdom
Join the people creating a one-stop shop for financial freedom
๐1
Atlassian is hiring!
Position: Data Engineer, Analytics & Data Science
Qualifications: Bachelorโs/ Masterโs Degree
Salary: 15 - 21 LPA (Expected)
Experience: 1 - 2 (Years)
Location: Bengaluru, India
๐Apply Now: https://careers-apac-atlassian.icims.com/jobs/17667/data-engineer/job?iis=LinkedIn&iisn=LinkedIn_Job_Ad&mobile=false&width=1215&height=500&bga=true&needsRedirect=false&jan1offset=330&jun1offset=330
Like for more โค๏ธ
Position: Data Engineer, Analytics & Data Science
Qualifications: Bachelorโs/ Masterโs Degree
Salary: 15 - 21 LPA (Expected)
Experience: 1 - 2 (Years)
Location: Bengaluru, India
๐Apply Now: https://careers-apac-atlassian.icims.com/jobs/17667/data-engineer/job?iis=LinkedIn&iisn=LinkedIn_Job_Ad&mobile=false&width=1215&height=500&bga=true&needsRedirect=false&jan1offset=330&jun1offset=330
Like for more โค๏ธ
Australia | India Careers (External)
Data Engineer in Bengaluru | Careers at Bengaluru - India
Working at Atlassian
Atlassians can choose where they work โ whether in an office, from home, or a combination of the two. That way, Atlassians have more control over supporting their family, personal goals, and other priorities. We can hire people in anyโฆ
Atlassians can choose where they work โ whether in an office, from home, or a combination of the two. That way, Atlassians have more control over supporting their family, personal goals, and other priorities. We can hire people in anyโฆ
โค1
python cheetsheet.pdf
2.4 MB
*Python*
โ High-Level & Easy to Learn โ Simple syntax, readable code, and beginner-friendly.
โ Interpreted Language โ No need for compilation; executed line by line.
โ Dynamically Typed โ No need to declare variable types; Python determines them at runtime.
โ Versatile & Multi-Purpose โ Used in Web Development, Data Science, AI, ML, Automation, Cybersecurity, and more.
โ Extensive Libraries & Frameworks โ Supports TensorFlow, NumPy, Pandas, Flask, Django, OpenCV, etc.
โ Object-Oriented & Functional โ Supports both OOP and functional programming paradigms.
โ Cross-Platform โ Runs on Windows, macOS, Linux, and even mobile devices.
โ Large Community & Support โ One of the most widely used languages with extensive documentation and forums.
โ Automation & Scripting โ Ideal for task automation, web scraping, and workflow management.
โ Strong Integration โ Works with C, C++, Java, SQL, and various APIs.
โ High-Level & Easy to Learn โ Simple syntax, readable code, and beginner-friendly.
โ Interpreted Language โ No need for compilation; executed line by line.
โ Dynamically Typed โ No need to declare variable types; Python determines them at runtime.
โ Versatile & Multi-Purpose โ Used in Web Development, Data Science, AI, ML, Automation, Cybersecurity, and more.
โ Extensive Libraries & Frameworks โ Supports TensorFlow, NumPy, Pandas, Flask, Django, OpenCV, etc.
โ Object-Oriented & Functional โ Supports both OOP and functional programming paradigms.
โ Cross-Platform โ Runs on Windows, macOS, Linux, and even mobile devices.
โ Large Community & Support โ One of the most widely used languages with extensive documentation and forums.
โ Automation & Scripting โ Ideal for task automation, web scraping, and workflow management.
โ Strong Integration โ Works with C, C++, Java, SQL, and various APIs.
๐4
Learn SQL from basic to advanced level in 30 days
Week 1: SQL Basics
Day 1: Introduction to SQL and Relational Databases
Overview of SQL Syntax
Setting up a Database (MySQL, PostgreSQL, or SQL Server)
Day 2: Data Types (Numeric, String, Date, etc.)
Writing Basic SQL Queries:
SELECT, FROM
Day 3: WHERE Clause for Filtering Data
Using Logical Operators:
AND, OR, NOT
Day 4: Sorting Data: ORDER BY
Limiting Results: LIMIT and OFFSET
Understanding DISTINCT
Day 5: Aggregate Functions:
COUNT, SUM, AVG, MIN, MAX
Day 6: Grouping Data: GROUP BY and HAVING
Combining Filters with Aggregations
Day 7: Review Week 1 Topics with Hands-On Practice
Solve SQL Exercises on platforms like HackerRank, LeetCode, or W3Schools
Week 2: Intermediate SQL
Day 8: SQL JOINS:
INNER JOIN, LEFT JOIN
Day 9: SQL JOINS Continued: RIGHT JOIN, FULL OUTER JOIN, SELF JOIN
Day 10: Working with NULL Values
Using Conditional Logic with CASE Statements
Day 11: Subqueries: Simple Subqueries (Single-row and Multi-row)
Correlated Subqueries
Day 12: String Functions:
CONCAT, SUBSTRING, LENGTH, REPLACE
Day 13: Date and Time Functions: NOW, CURDATE, DATEDIFF, DATEADD
Day 14: Combining Results: UNION, UNION ALL, INTERSECT, EXCEPT
Review Week 2 Topics and Practice
Week 3: Advanced SQL
Day 15: Common Table Expressions (CTEs)
WITH Clauses and Recursive Queries
Day 16: Window Functions:
ROW_NUMBER, RANK, DENSE_RANK, NTILE
Day 17: More Window Functions:
LEAD, LAG, FIRST_VALUE, LAST_VALUE
Day 18: Creating and Managing Views
Temporary Tables and Table Variables
Day 19: Transactions and ACID Properties
Working with Indexes for Query Optimization
Day 20: Error Handling in SQL
Writing Dynamic SQL Queries
Day 21: Review Week 3 Topics with Complex Query Practice
Solve Intermediate to Advanced SQL Challenges
Week 4: Database Management and Advanced Applications
Day 22: Database Design and Normalization:
1NF, 2NF, 3NF
Day 23: Constraints in SQL:
PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, DEFAULT
Day 24: Creating and Managing Indexes
Understanding Query Execution Plans
Day 25: Backup and Restore Strategies in SQL
Role-Based Permissions
Day 26: Pivoting and Unpivoting Data
Working with JSON and XML in SQL
Day 27: Writing Stored Procedures and Functions
Automating Processes with Triggers
Day 28: Integrating SQL with Other Tools (e.g., Python, Power BI, Tableau)
SQL in Big Data: Introduction to NoSQL
Day 29: Query Performance Tuning:
Tips and Tricks to Optimize SQL Queries
Day 30: Final Review of All Topics
Attempt SQL Projects or Case Studies (e.g., analyzing sales data, building a reporting dashboard)
Since SQL is one of the most essential skill for data analysts, I have decided to teach each topic daily in this channel for free.
Like this post if you want me to continue this SQL series ๐โฅ๏ธ
Hope it helps:)
Week 1: SQL Basics
Day 1: Introduction to SQL and Relational Databases
Overview of SQL Syntax
Setting up a Database (MySQL, PostgreSQL, or SQL Server)
Day 2: Data Types (Numeric, String, Date, etc.)
Writing Basic SQL Queries:
SELECT, FROM
Day 3: WHERE Clause for Filtering Data
Using Logical Operators:
AND, OR, NOT
Day 4: Sorting Data: ORDER BY
Limiting Results: LIMIT and OFFSET
Understanding DISTINCT
Day 5: Aggregate Functions:
COUNT, SUM, AVG, MIN, MAX
Day 6: Grouping Data: GROUP BY and HAVING
Combining Filters with Aggregations
Day 7: Review Week 1 Topics with Hands-On Practice
Solve SQL Exercises on platforms like HackerRank, LeetCode, or W3Schools
Week 2: Intermediate SQL
Day 8: SQL JOINS:
INNER JOIN, LEFT JOIN
Day 9: SQL JOINS Continued: RIGHT JOIN, FULL OUTER JOIN, SELF JOIN
Day 10: Working with NULL Values
Using Conditional Logic with CASE Statements
Day 11: Subqueries: Simple Subqueries (Single-row and Multi-row)
Correlated Subqueries
Day 12: String Functions:
CONCAT, SUBSTRING, LENGTH, REPLACE
Day 13: Date and Time Functions: NOW, CURDATE, DATEDIFF, DATEADD
Day 14: Combining Results: UNION, UNION ALL, INTERSECT, EXCEPT
Review Week 2 Topics and Practice
Week 3: Advanced SQL
Day 15: Common Table Expressions (CTEs)
WITH Clauses and Recursive Queries
Day 16: Window Functions:
ROW_NUMBER, RANK, DENSE_RANK, NTILE
Day 17: More Window Functions:
LEAD, LAG, FIRST_VALUE, LAST_VALUE
Day 18: Creating and Managing Views
Temporary Tables and Table Variables
Day 19: Transactions and ACID Properties
Working with Indexes for Query Optimization
Day 20: Error Handling in SQL
Writing Dynamic SQL Queries
Day 21: Review Week 3 Topics with Complex Query Practice
Solve Intermediate to Advanced SQL Challenges
Week 4: Database Management and Advanced Applications
Day 22: Database Design and Normalization:
1NF, 2NF, 3NF
Day 23: Constraints in SQL:
PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, DEFAULT
Day 24: Creating and Managing Indexes
Understanding Query Execution Plans
Day 25: Backup and Restore Strategies in SQL
Role-Based Permissions
Day 26: Pivoting and Unpivoting Data
Working with JSON and XML in SQL
Day 27: Writing Stored Procedures and Functions
Automating Processes with Triggers
Day 28: Integrating SQL with Other Tools (e.g., Python, Power BI, Tableau)
SQL in Big Data: Introduction to NoSQL
Day 29: Query Performance Tuning:
Tips and Tricks to Optimize SQL Queries
Day 30: Final Review of All Topics
Attempt SQL Projects or Case Studies (e.g., analyzing sales data, building a reporting dashboard)
Since SQL is one of the most essential skill for data analysts, I have decided to teach each topic daily in this channel for free.
Like this post if you want me to continue this SQL series ๐โฅ๏ธ
Hope it helps:)
๐21โค7๐1
๐4
DA charts.pdf
607.4 KB
๐ Master Data Visualization & Charts for Data Analysis!
Want to make your data analysis more insightful with stunning visualizations? ๐โจ Learn how to use charts, graphs, and dashboards to uncover hidden patterns and tell compelling data stories!
Turn your raw data into clear, meaningful, and powerful visual insights today! ๐ฅ
Want to make your data analysis more insightful with stunning visualizations? ๐โจ Learn how to use charts, graphs, and dashboards to uncover hidden patterns and tell compelling data stories!
Turn your raw data into clear, meaningful, and powerful visual insights today! ๐ฅ
๐ฅ4๐2
Day 1: Introduction to SQL and Relational Databases
Welcome to Day 1 of your SQL learning journey! ๐
SQL (Structured Query Language) is the language of databases and is widely used for managing and analyzing data. Whether you're aiming for a career in Data Science, Data Analysis, Web Development, or Finance, SQL is an essential skill to master.
---
๐ What is SQL?
SQL stands for Structured Query Language and is used to communicate with databases. It helps you store, retrieve, manipulate, and manage data in a structured way.
Imagine a library database where details of books (title, author, genre, availability) are stored in tables. With SQL, you can:
โ Find a book by its title
โ Get a list of all books by a specific author
โ Check how many books are available in a genre
โ Add new books to the library collection
โ Delete outdated records
---
๐ What is a Database?
A database is an organized collection of data that allows easy access, management, and updating.
There are two main types of databases:
1๏ธโฃ Relational Databases (RDBMS): Data is stored in tables (like Excel). Examples: MySQL, PostgreSQL, SQL Server, SQLite.
2๏ธโฃ Non-Relational Databases (NoSQL): Data is stored in key-value pairs, JSON, or documents. Examples: MongoDB, Firebase.
SQL works with Relational Databases (RDBMS).
---
๐ What is a Table?
A table is like a spreadsheet in Excel, with rows and columns.
๐ Example: A simple "Students" table
| Student_ID | Name | Age | Grade |
|------------|-------|-----|--------|
| 1 | Alex | 18 | A |
| 2 | Emma | 19 | B |
| 3 | John | 18 | A |
Each row represents a student, and each column stores a specific type of data (ID, Name, Age, Grade).
---
๐ SQL Commands Overview
SQL has different types of commands to manage data:
๐น Data Query Language (DQL) โ Used for fetching data
๐ธ
๐น Data Manipulation Language (DML) โ Used for modifying data
๐ธ
๐ธ
๐ธ
๐น Data Definition Language (DDL) โ Used for creating and modifying tables
๐ธ
๐ธ
๐ธ
๐น Data Control Language (DCL) โ Used for user permissions
๐ธ
๐ธ
๐น Transaction Control Language (TCL) โ Used for managing transactions
๐ธ
๐ธ
---
๐ Setting Up a Database
To practice SQL, you need a database environment. You can use:
1๏ธโฃ Online SQL Editors โ No installation needed
- [SQL Fiddle](http://sqlfiddle.com/)
- [W3Schools SQL Editor](https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all)
2๏ธโฃ Install a Database Software
- MySQL (Popular for beginners) โ [Download](https://www.mysql.com/downloads/)
- PostgreSQL (Advanced features) โ [Download](https://www.postgresql.org/download/)
- SQL Server (Used in enterprises) โ [Download](https://www.microsoft.com/en-us/sql-server/sql-server-downloads)
---
๐ Writing Your First SQL Query
Letโs retrieve all data from a Students table using the
Explanation:
-
-
-
---
๐ฏ Task for Today
1๏ธโฃ Understand the basic SQL commands mentioned above.
2๏ธโฃ Try an online SQL editor and execute
3๏ธโฃ Install MySQL or PostgreSQL (optional, but recommended).
---
๐ Thatโs it for Day 1! Tomorrow, weโll learn about SQL Data Types and start writing basic queries. ๐
๐ก Like & comment if you're excited to continue this series! ๐โค๏ธ
Welcome to Day 1 of your SQL learning journey! ๐
SQL (Structured Query Language) is the language of databases and is widely used for managing and analyzing data. Whether you're aiming for a career in Data Science, Data Analysis, Web Development, or Finance, SQL is an essential skill to master.
---
๐ What is SQL?
SQL stands for Structured Query Language and is used to communicate with databases. It helps you store, retrieve, manipulate, and manage data in a structured way.
Imagine a library database where details of books (title, author, genre, availability) are stored in tables. With SQL, you can:
โ Find a book by its title
โ Get a list of all books by a specific author
โ Check how many books are available in a genre
โ Add new books to the library collection
โ Delete outdated records
---
๐ What is a Database?
A database is an organized collection of data that allows easy access, management, and updating.
There are two main types of databases:
1๏ธโฃ Relational Databases (RDBMS): Data is stored in tables (like Excel). Examples: MySQL, PostgreSQL, SQL Server, SQLite.
2๏ธโฃ Non-Relational Databases (NoSQL): Data is stored in key-value pairs, JSON, or documents. Examples: MongoDB, Firebase.
SQL works with Relational Databases (RDBMS).
---
๐ What is a Table?
A table is like a spreadsheet in Excel, with rows and columns.
๐ Example: A simple "Students" table
| Student_ID | Name | Age | Grade |
|------------|-------|-----|--------|
| 1 | Alex | 18 | A |
| 2 | Emma | 19 | B |
| 3 | John | 18 | A |
Each row represents a student, and each column stores a specific type of data (ID, Name, Age, Grade).
---
๐ SQL Commands Overview
SQL has different types of commands to manage data:
๐น Data Query Language (DQL) โ Used for fetching data
๐ธ
SELECT โ Retrieve data from tables ๐น Data Manipulation Language (DML) โ Used for modifying data
๐ธ
INSERT โ Add new data ๐ธ
UPDATE โ Modify existing data ๐ธ
DELETE โ Remove data ๐น Data Definition Language (DDL) โ Used for creating and modifying tables
๐ธ
CREATE TABLE โ Create a new table ๐ธ
ALTER TABLE โ Modify table structure ๐ธ
DROP TABLE โ Delete a table ๐น Data Control Language (DCL) โ Used for user permissions
๐ธ
GRANT โ Give permissions ๐ธ
REVOKE โ Remove permissions ๐น Transaction Control Language (TCL) โ Used for managing transactions
๐ธ
COMMIT โ Save changes permanently ๐ธ
ROLLBACK โ Undo changes ---
๐ Setting Up a Database
To practice SQL, you need a database environment. You can use:
1๏ธโฃ Online SQL Editors โ No installation needed
- [SQL Fiddle](http://sqlfiddle.com/)
- [W3Schools SQL Editor](https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all)
2๏ธโฃ Install a Database Software
- MySQL (Popular for beginners) โ [Download](https://www.mysql.com/downloads/)
- PostgreSQL (Advanced features) โ [Download](https://www.postgresql.org/download/)
- SQL Server (Used in enterprises) โ [Download](https://www.microsoft.com/en-us/sql-server/sql-server-downloads)
---
๐ Writing Your First SQL Query
Letโs retrieve all data from a Students table using the
SELECT statement. SELECT * FROM Students;
Explanation:
-
SELECT โ Tells SQL to retrieve data -
* โ Means "all columns" -
FROM Students โ Specifies the table name ---
๐ฏ Task for Today
1๏ธโฃ Understand the basic SQL commands mentioned above.
2๏ธโฃ Try an online SQL editor and execute
SELECT * FROM Students; 3๏ธโฃ Install MySQL or PostgreSQL (optional, but recommended).
---
๐ Thatโs it for Day 1! Tomorrow, weโll learn about SQL Data Types and start writing basic queries. ๐
๐ก Like & comment if you're excited to continue this series! ๐โค๏ธ
Sqlfiddle
SQL Fiddle - Online SQL Compiler for learning & practice
Discover our free online SQL editor enhanced with AI to chat, explain, and generate code. Support SQL Server, MySQL, MariaDB, PostgreSQL, and SQLite.
๐15๐ฅ5
Day 2: SQL Data Types and Writing Basic Queries
Welcome to Day 2 of your SQL learning journey! ๐
Today, weโll cover two important topics:
โ Data Types in SQL โ Understanding different types of data in a database
โ Writing Basic SQL Queries โ Learning how to retrieve data using SQL
By the end of this lesson, youโll be able to create a table and write your first SQL query to fetch data! ๐
---
๐ What Are Data Types in SQL?
A data type defines the kind of data a column can store. Each column in a table must have a specific data type to ensure that data is stored correctly.
For example, a "Name" column should store text, while an "Age" column should store numbers.
---
๐ Common SQL Data Types (MySQL, PostgreSQL, SQL Server)
1๏ธโฃ Numeric Data Types (Used for storing numbers)
| Data Type | Description | Example |
|-----------|------------|---------|
|
|
|
๐น Example: If youโre storing student ages, use
---
2๏ธโฃ String (Text) Data Types
| Data Type | Description | Example |
|-----------|------------|---------|
|
|
|
๐น Example: A column storing names should be
---
3๏ธโฃ Date and Time Data Types
| Data Type | Description | Example |
|-----------|------------|---------|
|
|
|
|
๐น Example: If youโre storing a studentโs birth date, use
---
๐ Creating a Table in SQL
Now that we understand data types, letโs create a table for our students.
๐น Explanation:
-
-
-
-
-
-
---
๐ Writing Basic SQL Queries
Now, letโs insert some data and retrieve it using SQL queries.
1๏ธโฃ Inserting Data into a Table
๐น Explanation:
-
-
-
Now, letโs add a few more students:
---
2๏ธโฃ Retrieving Data Using `SELECT` Statement
To see all student records, use:
๐น Explanation:
-
-
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
---
Welcome to Day 2 of your SQL learning journey! ๐
Today, weโll cover two important topics:
โ Data Types in SQL โ Understanding different types of data in a database
โ Writing Basic SQL Queries โ Learning how to retrieve data using SQL
By the end of this lesson, youโll be able to create a table and write your first SQL query to fetch data! ๐
---
๐ What Are Data Types in SQL?
A data type defines the kind of data a column can store. Each column in a table must have a specific data type to ensure that data is stored correctly.
For example, a "Name" column should store text, while an "Age" column should store numbers.
---
๐ Common SQL Data Types (MySQL, PostgreSQL, SQL Server)
1๏ธโฃ Numeric Data Types (Used for storing numbers)
| Data Type | Description | Example |
|-----------|------------|---------|
|
INT | Stores whole numbers | 25, 100, -50 | |
DECIMAL(p, s) | Stores decimal numbers with precision | 12.34, 99.99 | |
FLOAT / REAL | Stores floating-point numbers | 1.23, 3.14 | ๐น Example: If youโre storing student ages, use
INT. If youโre storing bank balances, use DECIMAL. ---
2๏ธโฃ String (Text) Data Types
| Data Type | Description | Example |
|-----------|------------|---------|
|
CHAR(n) | Fixed-length string (n characters) | 'A', 'USA' | |
VARCHAR(n) | Variable-length string (up to n characters) | 'John Doe', 'Hello World' | |
TEXT | Large text data | 'This is a long description...' | ๐น Example: A column storing names should be
VARCHAR(50), meaning it can hold up to 50 characters. ---
3๏ธโฃ Date and Time Data Types
| Data Type | Description | Example |
|-----------|------------|---------|
|
DATE | Stores only the date (YYYY-MM-DD) | '2025-02-02' | |
TIME | Stores only the time (HH:MM:SS) | '14:30:00' | |
DATETIME | Stores both date and time | '2025-02-02 14:30:00' | |
TIMESTAMP | Stores date & time (used for logging) | '2025-02-02 14:30:00' | ๐น Example: If youโre storing a studentโs birth date, use
DATE. If youโre storing when a student logged in, use DATETIME. ---
๐ Creating a Table in SQL
Now that we understand data types, letโs create a table for our students.
CREATE TABLE Students (
Student_ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Grade CHAR(1),
Enrollment_Date DATE
);
๐น Explanation:
-
CREATE TABLE Students โ Creates a table named Students -
Student_ID INT PRIMARY KEY โ Unique ID for each student -
Name VARCHAR(50) โ Stores student names (up to 50 characters) -
Age INT โ Stores student ages -
Grade CHAR(1) โ Stores single-character grades (A, B, C...) -
Enrollment_Date DATE โ Stores the date of enrollment ---
๐ Writing Basic SQL Queries
Now, letโs insert some data and retrieve it using SQL queries.
1๏ธโฃ Inserting Data into a Table
INSERT INTO Students (Student_ID, Name, Age, Grade, Enrollment_Date)
VALUES (1, 'John Doe', 18, 'A', '2023-09-01');
๐น Explanation:
-
INSERT INTO Students โ Adds a new record to the Students table -
(Student_ID, Name, Age, Grade, Enrollment_Date) โ Specifies the columns -
VALUES (1, 'John Doe', 18, 'A', '2023-09-01') โ Provides the values Now, letโs add a few more students:
INSERT INTO Students (Student_ID, Name, Age, Grade, Enrollment_Date)
VALUES
(2, 'Emma Smith', 19, 'B', '2022-08-15'),
(3, 'Alex Brown', 20, 'A', '2021-07-10'),
(4, 'Sophia Johnson', 18, 'C', '2023-01-20');
---
2๏ธโฃ Retrieving Data Using `SELECT` Statement
To see all student records, use:
SELECT * FROM Students;
๐น Explanation:
-
SELECT * โ Selects all columns -
FROM Students โ Specifies the Students table ๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
---
๐5โค1
3๏ธโฃ Retrieving Specific Columns
If you only want to see the Name and Age, run:
๐น Output:
| Name | Age |
|--------------|----|
| John Doe | 18 |
| Emma Smith | 19 |
| Alex Brown | 20 |
| Sophia Johnson| 18 |
---
4๏ธโฃ Filtering Data Using `WHERE` Clause
Find students who are 18 years old:
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
---
5๏ธโฃ Using Conditions (`AND`, `OR`)
Find students who are 18 years old and have Grade A:
Find students who are either 18 or 19 years old:
---
๐ฏ Task for Today
1๏ธโฃ Understand SQL data types and their usage.
2๏ธโฃ Create a Students table in an SQL editor.
3๏ธโฃ Insert at least 5 records into your table.
4๏ธโฃ Write `SELECT` queries to retrieve:
โ All students
โ Students aged 18
โ Only Name and Age
---
๐ Thatโs it for Day 2! Tomorrow, weโll learn about the WHERE clause and logical operators for filtering data efficiently. ๐
๐ก Like & comment if you're excited for Day 3! ๐โค๏ธ
If you only want to see the Name and Age, run:
SELECT Name, Age FROM Students;
๐น Output:
| Name | Age |
|--------------|----|
| John Doe | 18 |
| Emma Smith | 19 |
| Alex Brown | 20 |
| Sophia Johnson| 18 |
---
4๏ธโฃ Filtering Data Using `WHERE` Clause
Find students who are 18 years old:
SELECT * FROM Students WHERE Age = 18;
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
---
5๏ธโฃ Using Conditions (`AND`, `OR`)
Find students who are 18 years old and have Grade A:
SELECT * FROM Students WHERE Age = 18 AND Grade = 'A';
Find students who are either 18 or 19 years old:
SELECT * FROM Students WHERE Age = 18 OR Age = 19;
---
๐ฏ Task for Today
1๏ธโฃ Understand SQL data types and their usage.
2๏ธโฃ Create a Students table in an SQL editor.
3๏ธโฃ Insert at least 5 records into your table.
4๏ธโฃ Write `SELECT` queries to retrieve:
โ All students
โ Students aged 18
โ Only Name and Age
---
๐ Thatโs it for Day 2! Tomorrow, weโll learn about the WHERE clause and logical operators for filtering data efficiently. ๐
๐ก Like & comment if you're excited for Day 3! ๐โค๏ธ
๐4โค3
Day 3: Filtering Data Using the `WHERE` Clause and Logical Operators (`AND`, `OR`, `NOT`)
Welcome to Day 3 of your SQL journey! ๐
Yesterday, we learned about SQL data types and basic queries using `SELECT`. Today, we will take it further and learn how to filter data using the
By the end of this lesson, youโll be able to retrieve specific data based on conditions! ๐
---
๐ What is the `WHERE` Clause?
In real-world databases, tables contain thousands or even millions of records. If you only want to find specific data, you need a filtering method.
The
๐ Syntax:
---
๐ Using `WHERE` to Filter Data
Letโs take an example. We have a Students table with the following records:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
---
1๏ธโฃ Filtering Data with `WHERE` Clause
Example 1: Find all students who are 18 years old
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
โ Explanation:
- The query only selects students where
---
2๏ธโฃ Using `AND` Operator
The `AND` operator allows us to filter based on multiple conditions.
Example 2: Find students who are 18 years old AND have Grade A
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
โ Explanation:
- The query filters students who are both 18 years old AND have Grade A.
---
3๏ธโฃ Using `OR` Operator
The `OR` operator allows us to filter if at least one condition is met.
Example 3: Find students who are either 18 OR 19 years old
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
โ Explanation:
- The query selects students who are either 18 OR 19 years old.
---
4๏ธโฃ Using `NOT` Operator
The `NOT` operator helps us find records that do NOT match a certain condition.
Example 4: Find students who are NOT 18 years old
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|-----------|-----|-------|----------------|
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
โ Explanation:
- The query excludes students who are 18 years old.
---
๐ Combining `AND`, `OR`, and `NOT`
Example 5: Find students who are either Grade A OR Grade B, but NOT 18 years old
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|-----------|-----|-------|----------------|
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
โ Explanation:
- The query selects students who have Grade A OR B.
- But it excludes students who are 18 years old.
---
๐ Using Comparison Operators with `WHERE`
Welcome to Day 3 of your SQL journey! ๐
Yesterday, we learned about SQL data types and basic queries using `SELECT`. Today, we will take it further and learn how to filter data using the
WHERE clause and logical operators (AND, OR, NOT). By the end of this lesson, youโll be able to retrieve specific data based on conditions! ๐
---
๐ What is the `WHERE` Clause?
In real-world databases, tables contain thousands or even millions of records. If you only want to find specific data, you need a filtering method.
The
WHERE clause allows us to retrieve only the records that match certain conditions instead of displaying the entire table. ๐ Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
---
๐ Using `WHERE` to Filter Data
Letโs take an example. We have a Students table with the following records:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
---
1๏ธโฃ Filtering Data with `WHERE` Clause
Example 1: Find all students who are 18 years old
SELECT * FROM Students WHERE Age = 18;
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
โ Explanation:
- The query only selects students where
Age = 18. ---
2๏ธโฃ Using `AND` Operator
The `AND` operator allows us to filter based on multiple conditions.
Example 2: Find students who are 18 years old AND have Grade A
SELECT * FROM Students WHERE Age = 18 AND Grade = 'A';
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
โ Explanation:
- The query filters students who are both 18 years old AND have Grade A.
---
3๏ธโฃ Using `OR` Operator
The `OR` operator allows us to filter if at least one condition is met.
Example 3: Find students who are either 18 OR 19 years old
SELECT * FROM Students WHERE Age = 18 OR Age = 19;
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
โ Explanation:
- The query selects students who are either 18 OR 19 years old.
---
4๏ธโฃ Using `NOT` Operator
The `NOT` operator helps us find records that do NOT match a certain condition.
Example 4: Find students who are NOT 18 years old
SELECT * FROM Students WHERE NOT Age = 18;
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|-----------|-----|-------|----------------|
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
โ Explanation:
- The query excludes students who are 18 years old.
---
๐ Combining `AND`, `OR`, and `NOT`
Example 5: Find students who are either Grade A OR Grade B, but NOT 18 years old
SELECT * FROM Students WHERE (Grade = 'A' OR Grade = 'B') AND NOT Age = 18;
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|-----------|-----|-------|----------------|
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
โ Explanation:
- The query selects students who have Grade A OR B.
- But it excludes students who are 18 years old.
---
๐ Using Comparison Operators with `WHERE`
๐2โค1
| Operator | Meaning |
|----------|---------|
|
|
|
|
|
|
Example 6: Find students older than 18 years
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|-----------|-----|-------|----------------|
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
โ Explanation:
- The query selects students who are older than 18.
---
## ๐ฏ Task for Today
โ Write a query to find students who are exactly 19 years old.
โ Write a query to find students who are younger than 19.
โ Write a query to find students who are either 18 OR 20 years old.
โ Write a query to find students who are not Grade A.
โ Write a query to find students who are older than 18 AND have Grade B.
---
๐ Summary
โ
โ
โ
โ
โ We can combine multiple conditions using
---
๐ Thatโs it for Day 3! Tomorrow, weโll learn about sorting data using `ORDER BY`, limiting results with `LIMIT`, and removing duplicates using `DISTINCT`. ๐
Share with Credit: https://t.me/codingdidi
๐ก Like & comment if you're excited for Day 4! ๐โค๏ธ
|----------|---------|
|
= | Equals ||
!= or <> | Not Equal ||
> | Greater than ||
< | Less than ||
>= | Greater than or equal to ||
<= | Less than or equal to |Example 6: Find students older than 18 years
SELECT * FROM Students WHERE Age > 18;
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|-----------|-----|-------|----------------|
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
โ Explanation:
- The query selects students who are older than 18.
---
## ๐ฏ Task for Today
โ Write a query to find students who are exactly 19 years old.
โ Write a query to find students who are younger than 19.
โ Write a query to find students who are either 18 OR 20 years old.
โ Write a query to find students who are not Grade A.
โ Write a query to find students who are older than 18 AND have Grade B.
---
๐ Summary
โ
WHERE filters records based on a condition. โ
AND requires both conditions to be met. โ
OR requires at least one condition to be met. โ
NOT excludes specific records. โ We can combine multiple conditions using
AND, OR, and NOT. ---
๐ Thatโs it for Day 3! Tomorrow, weโll learn about sorting data using `ORDER BY`, limiting results with `LIMIT`, and removing duplicates using `DISTINCT`. ๐
Share with Credit: https://t.me/codingdidi
๐ก Like & comment if you're excited for Day 4! ๐โค๏ธ
Telegram
@Codingdidi
Free learning Resources For Data Analysts, Data science, ML, AI, GEN AI and Job updates, career growth, Tech updates
๐4
This is how you can learn everything:
1. 25 minutes of focused learning
2. 5 minutes break
3. 25 minutes of focused learning
4. 25 minutes break minimum
5. Optionally go back to step 1
You can complete this cycle 2 times max per day, and it works wonders.
1. 25 minutes of focused learning
2. 5 minutes break
3. 25 minutes of focused learning
4. 25 minutes break minimum
5. Optionally go back to step 1
You can complete this cycle 2 times max per day, and it works wonders.
๐4๐ฅ1
Hi, all
Your inputs are helping me make this SQL series more informative.
Do comments your inputs. โ
Happy Learning ๐
Your inputs are helping me make this SQL series more informative.
Do comments your inputs. โ
Happy Learning ๐
Day 4: Sorting Data (`ORDER BY`), Limiting Results (`LIMIT`, `OFFSET`), and Removing Duplicates (`DISTINCT`)
Welcome to Day 4 of learning SQL! ๐
Yesterday, we learned how to filter data using `WHERE` and logical operators (
โ Sort data using `ORDER BY`
โ Limit the number of results using `LIMIT` and `OFFSET`
โ Remove duplicate values using `DISTINCT`
By the end of this lesson, youโll be able to organize and refine your query results efficiently! ๐
---
๐ Sorting Data Using `ORDER BY`
๐น Why Do We Need Sorting?
When you query a table, the results might appear in random order. If you want your data to be more organized and meaningful, you need to sort it based on a specific column.
๐ Syntax:
-
-
---
1๏ธโฃ Sorting in Ascending Order (`ASC`)
Letโs use a Students table as an example:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
Example 1: Sort students by Age (Ascending)
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
โ Explanation:
- The records are sorted from youngest (18) to oldest (20).
---
2๏ธโฃ Sorting in Descending Order (`DESC`)
Example 2: Sort students by Age (Descending)
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 3 | Alex Brown | 20 | A | 2021-07-10 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 1 | John Doe | 18 | A | 2023-09-01 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
โ Explanation:
- The records are sorted from oldest (20) to youngest (18).
---
3๏ธโฃ Sorting by Multiple Columns
If two students have the same age, you can sort further by another column, like Grade.
Example 3: Sort students by Age (Ascending), then by Grade (Ascending)
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
โ Explanation:
- Students are sorted by Age (smallest first).
- If two students have the same age, they are sorted by Grade (A before C).
---
๐ Limiting Results Using `LIMIT` and `OFFSET`
๐น Why Do We Need `LIMIT`?
Imagine you have 1 million records, but you only need to see the top 5 results. The
๐ Syntax:
Example 4: Get the Top 3 Youngest Students
Welcome to Day 4 of learning SQL! ๐
Yesterday, we learned how to filter data using `WHERE` and logical operators (
AND, OR, NOT). Today, weโll take it a step further and learn how to: โ Sort data using `ORDER BY`
โ Limit the number of results using `LIMIT` and `OFFSET`
โ Remove duplicate values using `DISTINCT`
By the end of this lesson, youโll be able to organize and refine your query results efficiently! ๐
---
๐ Sorting Data Using `ORDER BY`
๐น Why Do We Need Sorting?
When you query a table, the results might appear in random order. If you want your data to be more organized and meaningful, you need to sort it based on a specific column.
๐ Syntax:
SELECT column1, column2, ...
FROM table_name
ORDER BY column_name ASC/DESC;
-
ASC (Ascending Order) โ Default, sorts from smallest to largest (A-Z, 0-9). -
DESC (Descending Order) โ Sorts from largest to smallest (Z-A, 9-0). ---
1๏ธโฃ Sorting in Ascending Order (`ASC`)
Letโs use a Students table as an example:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
Example 1: Sort students by Age (Ascending)
SELECT * FROM Students ORDER BY Age ASC;
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
โ Explanation:
- The records are sorted from youngest (18) to oldest (20).
---
2๏ธโฃ Sorting in Descending Order (`DESC`)
Example 2: Sort students by Age (Descending)
SELECT * FROM Students ORDER BY Age DESC;
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 3 | Alex Brown | 20 | A | 2021-07-10 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 1 | John Doe | 18 | A | 2023-09-01 |
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
โ Explanation:
- The records are sorted from oldest (20) to youngest (18).
---
3๏ธโฃ Sorting by Multiple Columns
If two students have the same age, you can sort further by another column, like Grade.
Example 3: Sort students by Age (Ascending), then by Grade (Ascending)
SELECT * FROM Students ORDER BY Age ASC, Grade ASC;
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
| 3 | Alex Brown | 20 | A | 2021-07-10 |
โ Explanation:
- Students are sorted by Age (smallest first).
- If two students have the same age, they are sorted by Grade (A before C).
---
๐ Limiting Results Using `LIMIT` and `OFFSET`
๐น Why Do We Need `LIMIT`?
Imagine you have 1 million records, but you only need to see the top 5 results. The
LIMIT clause helps restrict the number of rows returned by a query. ๐ Syntax:
SELECT column1, column2, ...
FROM table_name
ORDER BY column_name
LIMIT number;
Example 4: Get the Top 3 Youngest Students
SELECT * FROM Students ORDER BY Age ASC LIMIT 3;
๐1
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
โ Explanation:
- We only get 3 results instead of the full table.
---
๐ Skipping Rows Using `OFFSET`
๐ Syntax:
Example 5: Get the second and third youngest students (Skip the first one)
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|-----------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith| 19 | B | 2022-08-15 |
โ Explanation:
- The first student (
---
๐ Removing Duplicates Using `DISTINCT`
๐น Why Do We Need `DISTINCT`?
Sometimes, a column contains repeated values, and you only need unique values.
๐ Syntax:
Example 6: Get All Unique Grades
๐น Output:
| Grade |
|-------|
| A |
| B |
| C |
โ Explanation:
- The query removes duplicate values from the Grade column.
---
๐ฏ Task for Today
โ Write a query to get the top 5 oldest students.
โ Write a query to list unique enrollment dates.
โ Write a query to get the second highest age student.
---
๐ Summary
โ
โ
โ
โ
Tomorrow, we will learn SQL Aggregate Functions (`COUNT`, `SUM`, `AVG`, `MIN`, `MAX`). ๐
Share with Credit: https://t.me/codingdidi
๐ก Like & Comment if you're ready for Day 5! ๐โค๏ธ
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|--------------|-----|-------|----------------|
| 4 | Sophia Johnson| 18 | C | 2023-01-20 |
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith | 19 | B | 2022-08-15 |
โ Explanation:
- We only get 3 results instead of the full table.
---
๐ Skipping Rows Using `OFFSET`
OFFSET is used with `LIMIT` to skip a specific number of rows before returning results. ๐ Syntax:
SELECT column1, column2, ...
FROM table_name
ORDER BY column_name
LIMIT number OFFSET number;
Example 5: Get the second and third youngest students (Skip the first one)
SELECT * FROM Students ORDER BY Age ASC LIMIT 2 OFFSET 1;
๐น Output:
| Student_ID | Name | Age | Grade | Enrollment_Date |
|------------|-----------|-----|-------|----------------|
| 1 | John Doe | 18 | A | 2023-09-01 |
| 2 | Emma Smith| 19 | B | 2022-08-15 |
โ Explanation:
- The first student (
Sophia Johnson, Age 18) is skipped, and the next 2 students are returned. ---
๐ Removing Duplicates Using `DISTINCT`
๐น Why Do We Need `DISTINCT`?
Sometimes, a column contains repeated values, and you only need unique values.
๐ Syntax:
SELECT DISTINCT column_name FROM table_name;
Example 6: Get All Unique Grades
SELECT DISTINCT Grade FROM Students;
๐น Output:
| Grade |
|-------|
| A |
| B |
| C |
โ Explanation:
- The query removes duplicate values from the Grade column.
---
๐ฏ Task for Today
โ Write a query to get the top 5 oldest students.
โ Write a query to list unique enrollment dates.
โ Write a query to get the second highest age student.
---
๐ Summary
โ
ORDER BY sorts data (Ascending/Descending). โ
LIMIT restricts the number of rows returned. โ
OFFSET skips a specific number of rows. โ
DISTINCT removes duplicate values. Tomorrow, we will learn SQL Aggregate Functions (`COUNT`, `SUM`, `AVG`, `MIN`, `MAX`). ๐
Share with Credit: https://t.me/codingdidi
๐ก Like & Comment if you're ready for Day 5! ๐โค๏ธ
Telegram
@Codingdidi
Free learning Resources For Data Analysts, Data science, ML, AI, GEN AI and Job updates, career growth, Tech updates
๐6
Day 5: SQL Aggregate Functions (`COUNT`, `SUM`, `AVG`, `MIN`, `MAX`)
Welcome to Day 5 of learning SQL! ๐
So far, weโve learned how to filter, sort, limit, and remove duplicates in our SQL queries. Today, we will take it one step further by learning Aggregate Functions in SQL.
๐น What Are Aggregate Functions?
Aggregate functions perform calculations on a group of rows and return a single value. These functions are useful when we want to summarize data, such as:
โ Counting the number of records (
โ Finding the total sum (
โ Calculating the average (
โ Finding the minimum value (
โ Finding the maximum value (
Letโs go step by step! ๐
---
๐ `COUNT()` โ Counting the Number of Rows
๐น Why Do We Need `COUNT()`?
We use
๐ Syntax:
-
-
---
Example 1: Count the Total Number of Students
Consider this Students table:
| Student_ID | Name | Age | Grade | Fees_Paid |
|------------|---------------|-----|-------|----------|
| 1 | John Doe | 18 | A | 1000 |
| 2 | Emma Smith | 19 | B | 1200 |
| 3 | Alex Brown | 20 | A | 900 |
| 4 | Sophia Johnson | 18 | C | NULL |
๐น Output:
| COUNT(*) |
|----------|
| 4 |
โ Explanation:
- This query counts all rows in the table.
---
Example 2: Count the Number of Students Who Paid Fees
๐น Output:
| COUNT(Fees_Paid) |
|------------------|
| 3 |
โ Explanation:
- This query excludes NULL values in
---
๐ `SUM()` โ Adding Up Values
๐น Why Do We Need `SUM()`?
๐ Syntax:
---
Example 3: Find the Total Fees Paid
๐น Output:
| SUM(Fees_Paid) |
|---------------|
| 3100 |
โ Explanation:
- The sum of 1000 + 1200 + 900 is 3100 (ignores NULL values).
---
๐ `AVG()` โ Finding the Average
๐น Why Do We Need `AVG()`?
๐ Syntax:
---
Example 4: Find the Average Fees Paid
๐น Output:
| AVG(Fees_Paid) |
|---------------|
| 1033.33 |
โ Explanation:
- The average is (1000 + 1200 + 900) รท 3 = 1033.33 (ignores NULL values).
---
๐ `MIN()` โ Finding the Minimum Value
๐น Why Do We Need `MIN()`?
๐ Syntax:
---
Example 5: Find the Youngest Studentโs Age
๐น Output:
| MIN(Age) |
|---------|
| 18 |
โ Explanation:
- The minimum age in the table is 18.
---
๐ `MAX()` โ Finding the Maximum Value
๐น Why Do We Need `MAX()`?
๐ Syntax:
---
Example 6: Find the Oldest Studentโs Age
๐น Output:
| MAX(Age) |
|---------|
| 20 |
โ Explanation:
- The maximum age in the table is 20.
---
๐ Combining Aggregate Functions
We can use multiple aggregate functions in a single query.
Example 7: Get All Summary Data
๐น Output:
| Total_Students | Total_Fees | Average_Fees | Youngest_Age | Oldest_Age |
|---------------|-----------|-------------|-------------|-----------|
| 4 | 3100 | 1033.33 | 18 | 20 |
โ Explanation:
- This query provides a complete summary of the student data.
---
Welcome to Day 5 of learning SQL! ๐
So far, weโve learned how to filter, sort, limit, and remove duplicates in our SQL queries. Today, we will take it one step further by learning Aggregate Functions in SQL.
๐น What Are Aggregate Functions?
Aggregate functions perform calculations on a group of rows and return a single value. These functions are useful when we want to summarize data, such as:
โ Counting the number of records (
COUNT) โ Finding the total sum (
SUM) โ Calculating the average (
AVG) โ Finding the minimum value (
MIN) โ Finding the maximum value (
MAX) Letโs go step by step! ๐
---
๐ `COUNT()` โ Counting the Number of Rows
๐น Why Do We Need `COUNT()`?
We use
COUNT() to find how many rows exist in a table or how many times a specific value appears. ๐ Syntax:
SELECT COUNT(column_name) FROM table_name;
-
COUNT(column_name): Counts non-null values in a specific column. -
COUNT(*): Counts all rows, including those with NULL values. ---
Example 1: Count the Total Number of Students
Consider this Students table:
| Student_ID | Name | Age | Grade | Fees_Paid |
|------------|---------------|-----|-------|----------|
| 1 | John Doe | 18 | A | 1000 |
| 2 | Emma Smith | 19 | B | 1200 |
| 3 | Alex Brown | 20 | A | 900 |
| 4 | Sophia Johnson | 18 | C | NULL |
SELECT COUNT(*) FROM Students;
๐น Output:
| COUNT(*) |
|----------|
| 4 |
โ Explanation:
- This query counts all rows in the table.
---
Example 2: Count the Number of Students Who Paid Fees
SELECT COUNT(Fees_Paid) FROM Students;
๐น Output:
| COUNT(Fees_Paid) |
|------------------|
| 3 |
โ Explanation:
- This query excludes NULL values in
Fees_Paid. ---
๐ `SUM()` โ Adding Up Values
๐น Why Do We Need `SUM()`?
SUM() calculates the total sum of numeric values in a column. ๐ Syntax:
SELECT SUM(column_name) FROM table_name;
---
Example 3: Find the Total Fees Paid
SELECT SUM(Fees_Paid) FROM Students;
๐น Output:
| SUM(Fees_Paid) |
|---------------|
| 3100 |
โ Explanation:
- The sum of 1000 + 1200 + 900 is 3100 (ignores NULL values).
---
๐ `AVG()` โ Finding the Average
๐น Why Do We Need `AVG()`?
AVG() calculates the average (mean) value of a numeric column. ๐ Syntax:
SELECT AVG(column_name) FROM table_name;
---
Example 4: Find the Average Fees Paid
SELECT AVG(Fees_Paid) FROM Students;
๐น Output:
| AVG(Fees_Paid) |
|---------------|
| 1033.33 |
โ Explanation:
- The average is (1000 + 1200 + 900) รท 3 = 1033.33 (ignores NULL values).
---
๐ `MIN()` โ Finding the Minimum Value
๐น Why Do We Need `MIN()`?
MIN() returns the smallest value in a column. ๐ Syntax:
SELECT MIN(column_name) FROM table_name;
---
Example 5: Find the Youngest Studentโs Age
SELECT MIN(Age) FROM Students;
๐น Output:
| MIN(Age) |
|---------|
| 18 |
โ Explanation:
- The minimum age in the table is 18.
---
๐ `MAX()` โ Finding the Maximum Value
๐น Why Do We Need `MAX()`?
MAX() returns the largest value in a column. ๐ Syntax:
SELECT MAX(column_name) FROM table_name;
---
Example 6: Find the Oldest Studentโs Age
SELECT MAX(Age) FROM Students;
๐น Output:
| MAX(Age) |
|---------|
| 20 |
โ Explanation:
- The maximum age in the table is 20.
---
๐ Combining Aggregate Functions
We can use multiple aggregate functions in a single query.
Example 7: Get All Summary Data
SELECT
COUNT(*) AS Total_Students,
SUM(Fees_Paid) AS Total_Fees,
AVG(Fees_Paid) AS Average_Fees,
MIN(Age) AS Youngest_Age,
MAX(Age) AS Oldest_Age
FROM Students;
๐น Output:
| Total_Students | Total_Fees | Average_Fees | Youngest_Age | Oldest_Age |
|---------------|-----------|-------------|-------------|-----------|
| 4 | 3100 | 1033.33 | 18 | 20 |
โ Explanation:
- This query provides a complete summary of the student data.
---
โค1
๐ฏ Task for Today
โ Count the number of students in Grade A.
โ Find the total fees paid by students in Grade B.
โ Get the average age of students.
โ Find the highest and lowest fees paid.
---
๐ Summary
โ
โ
โ
โ
โ
Tomorrow, we will learn about SQL GROUP BY & HAVING. ๐
Share with Credit: https://t.me/codingdidi
๐ก Like & Comment if you're ready for Day 6! ๐โค๏ธ
โ Count the number of students in Grade A.
โ Find the total fees paid by students in Grade B.
โ Get the average age of students.
โ Find the highest and lowest fees paid.
---
๐ Summary
โ
COUNT() โ Counts the number of rows. โ
SUM() โ Adds up values. โ
AVG() โ Finds the average. โ
MIN() โ Finds the smallest value. โ
MAX() โ Finds the largest value. Tomorrow, we will learn about SQL GROUP BY & HAVING. ๐
Share with Credit: https://t.me/codingdidi
๐ก Like & Comment if you're ready for Day 6! ๐โค๏ธ
Telegram
@Codingdidi
Free learning Resources For Data Analysts, Data science, ML, AI, GEN AI and Job updates, career growth, Tech updates
๐4
Day 6: SQL `GROUP BY` and `HAVING` โ Grouping and Filtering Data
Welcome to Day 6 of learning SQL! ๐
Yesterday, we learned about aggregate functions (
For example, instead of finding the total fees paid by all students, what if we want to find the total fees paid per grade? Thatโs where
---
๐น Why Do We Need `GROUP BY`?
๐ Syntax:
-
-
---
๐ `GROUP BY` Example โ Total Fees Paid Per Grade
We will use the same Students table:
| Student_ID | Name | Age | Grade | Fees_Paid |
|------------|---------------|-----|-------|----------|
| 1 | John Doe | 18 | A | 1000 |
| 2 | Emma Smith | 19 | B | 1200 |
| 3 | Alex Brown | 20 | A | 900 |
| 4 | Sophia Johnson | 18 | C | NULL |
| 5 | Liam Davis | 19 | B | 1100 |
---
๐ธ Find the Total Fees Paid Per Grade
๐น Output:
| Grade | Total_Fees |
|-------|-----------|
| A | 1900 |
| B | 2300 |
| C | NULL |
โ Explanation:
- The query groups students by Grade.
- Then it calculates the total fees paid for each grade using
- Grade C shows NULL because Sophia hasn't paid fees (NULL values are ignored in
---
๐ธ Count the Number of Students in Each Grade
๐น Output:
| Grade | Total_Students |
|-------|---------------|
| A | 2 |
| B | 2 |
| C | 1 |
โ Explanation:
-
-
---
๐ `HAVING` Clause โ Filtering Groups
The
๐จ Use `HAVING` to filter groups after aggregation!
๐ Syntax:
---
๐ธ Find Grades Where Total Fees Paid is More Than 2000
๐น Output:
| Grade | Total_Fees |
|-------|-----------|
| B | 2300 |
โ Explanation:
- The query groups students by Grade and calculates total fees per grade.
-
- Grade A (1900) is excluded, but Grade B (2300) is included.
---
๐ธ Find Grades with More Than 1 Student
๐น Output:
| Grade | Total_Students |
|-------|---------------|
| A | 2 |
| B | 2 |
โ Explanation:
-
-
---
๐ `WHERE` vs. `HAVING` โ Key Differences
| Feature |
|----------|--------|---------|
| Filters individual rows before grouping | โ Yes | โ No |
| Filters groups after aggregation | โ No | โ Yes |
| Works with aggregate functions (
---
๐ฏ Task for Today
โ Find the total fees paid per grade but only show grades where fees are above 2000.
โ Count the number of students per age and show only ages where students are more than 1.
โ Find the average fees per grade and show only grades where the average fee is above 1000.
---
Welcome to Day 6 of learning SQL! ๐
Yesterday, we learned about aggregate functions (
COUNT, SUM, AVG, MIN, MAX) to summarize data. But what if we want to apply these functions to different groups of data? ๐ค For example, instead of finding the total fees paid by all students, what if we want to find the total fees paid per grade? Thatโs where
GROUP BY comes in! ๐ ---
๐น Why Do We Need `GROUP BY`?
GROUP BY helps us group rows with the same values in a column and then apply aggregate functions to each group separately. ๐ Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name;
-
column_name โ The column used for grouping. -
aggregate_function(column_name) โ Applies an aggregate function (e.g., SUM, AVG, COUNT, etc.) to each group. ---
๐ `GROUP BY` Example โ Total Fees Paid Per Grade
We will use the same Students table:
| Student_ID | Name | Age | Grade | Fees_Paid |
|------------|---------------|-----|-------|----------|
| 1 | John Doe | 18 | A | 1000 |
| 2 | Emma Smith | 19 | B | 1200 |
| 3 | Alex Brown | 20 | A | 900 |
| 4 | Sophia Johnson | 18 | C | NULL |
| 5 | Liam Davis | 19 | B | 1100 |
---
๐ธ Find the Total Fees Paid Per Grade
SELECT Grade, SUM(Fees_Paid) AS Total_Fees
FROM Students
GROUP BY Grade;
๐น Output:
| Grade | Total_Fees |
|-------|-----------|
| A | 1900 |
| B | 2300 |
| C | NULL |
โ Explanation:
- The query groups students by Grade.
- Then it calculates the total fees paid for each grade using
SUM(Fees_Paid). - Grade C shows NULL because Sophia hasn't paid fees (NULL values are ignored in
SUM()). ---
๐ธ Count the Number of Students in Each Grade
SELECT Grade, COUNT(*) AS Total_Students
FROM Students
GROUP BY Grade;
๐น Output:
| Grade | Total_Students |
|-------|---------------|
| A | 2 |
| B | 2 |
| C | 1 |
โ Explanation:
-
COUNT(*) counts all students in each grade. -
GROUP BY Grade groups them by grade before counting. ---
๐ `HAVING` Clause โ Filtering Groups
The
WHERE clause cannot be used with aggregate functions because it filters individual rows before grouping. ๐จ Use `HAVING` to filter groups after aggregation!
๐ Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name
HAVING condition;
---
๐ธ Find Grades Where Total Fees Paid is More Than 2000
SELECT Grade, SUM(Fees_Paid) AS Total_Fees
FROM Students
GROUP BY Grade
HAVING SUM(Fees_Paid) > 2000;
๐น Output:
| Grade | Total_Fees |
|-------|-----------|
| B | 2300 |
โ Explanation:
- The query groups students by Grade and calculates total fees per grade.
-
HAVING SUM(Fees_Paid) > 2000 filters only groups where the total fees paid exceeds 2000. - Grade A (1900) is excluded, but Grade B (2300) is included.
---
๐ธ Find Grades with More Than 1 Student
SELECT Grade, COUNT(*) AS Total_Students
FROM Students
GROUP BY Grade
HAVING COUNT(*) > 1;
๐น Output:
| Grade | Total_Students |
|-------|---------------|
| A | 2 |
| B | 2 |
โ Explanation:
-
COUNT(*) counts the number of students per grade. -
HAVING COUNT(*) > 1 filters out grades that have only 1 student (Grade C). ---
๐ `WHERE` vs. `HAVING` โ Key Differences
| Feature |
WHERE | HAVING ||----------|--------|---------|
| Filters individual rows before grouping | โ Yes | โ No |
| Filters groups after aggregation | โ No | โ Yes |
| Works with aggregate functions (
SUM, COUNT, etc.) | โ No | โ
Yes |---
๐ฏ Task for Today
โ Find the total fees paid per grade but only show grades where fees are above 2000.
โ Count the number of students per age and show only ages where students are more than 1.
โ Find the average fees per grade and show only grades where the average fee is above 1000.
---
โค4๐3
๐ Summary
โ
โ Aggregate functions (
โ
โ
Tomorrow, we will learn about SQL Joins (INNER JOIN, LEFT JOIN, etc.) to combine data from multiple tables! ๐
๐ก Like & Comment if you're ready for Day 7! ๐โค๏ธ
โ
GROUP BY โ Groups rows by a column. โ Aggregate functions (
SUM, AVG, COUNT, etc.) summarize each group. โ
HAVING filters groups after aggregation. โ
WHERE filters before grouping. Tomorrow, we will learn about SQL Joins (INNER JOIN, LEFT JOIN, etc.) to combine data from multiple tables! ๐
๐ก Like & Comment if you're ready for Day 7! ๐โค๏ธ