🔹 Introduction
In this section, you will learn SQL using MySQL step-by-step.
SQL (Structured Query Language) is used to interact with databases and retrieve data.
This guide is beginner-friendly and will help you understand how to query and analyze data using SQL.
Â
🟢 STEP 1 — WHAT IS SQL?
SQL stands for Structured Query Language.
It is used to:
- Retrieve data from databases
- Filter data
- Sort data
- Analyze data
SQL is an essential skill for data analysts.
SQL allows you to ask questions about your data and get answers instantly.
🟢 STEP 2 — WHAT IS MYSQL?
MySQL is a database management system used to store and manage data.
We use MySQL to run SQL queries and work with data tables.
Â
🟢 STEP 3 — MYSQL INTERFACE
When you open MySQL, you will see:
- Query Editor → where you write SQL queries
- Database panel → shows available databases
- Tables → where data is stored
You will write SQL commands in the query editor to interact with your data.
Â
🟢 STEP 4 — BASIC SQL STRUCTURE
A basic SQL query looks like this:
SELECT column _name
FROM table_ name;
FROM table_ name;
This is used to retrieve data from a table
SELECT STATEMENT
```text
SELECT is used to choose the columns you want.
Example:
SELECT Sales, Profit
FROM superstore;
Â
🟢 STEP 5— WHERE CLAUSE
WHERE is used to filter data.
Example:
SELECT *
FROM superstore
WHERE Category = 'Furniture';
FROM superstore
WHERE Category = 'Furniture';
Â
🟢 STEP 6 — ORDER BY
ORDER BY is used to sort data.
Example:
SELECT Sales
FROM superstore
ORDER BY Sales DESC;
FROM superstore
ORDER BY Sales DESC;
Â
🟢 STEP 7 — GROUP BY
GROUP BY is used to summarize data.
Example:
SELECT Category, SUM(Sales)
FROM superstore
GROUP BY Category;
FROM superstore
GROUP BY Category;
Â
🟢 STEP 8 — HAVING
HAVING is used to filter grouped data.
Example:
SELECT Category, SUM(Sales)
FROM superstore
GROUP BY Category
HAVING SUM(Sales) > 1000;
FROM superstore
GROUP BY Category
HAVING SUM(Sales) > 1000;
Â
🟢 STEP 9 — LIMIT
LIMIT is used to restrict the number of results.
Example:
SELECT *
FROM superstore
LIMIT 10;
FROM superstore
LIMIT 10;
Â
🔹 Understanding SQL Flow
SQL follows this logical order:
- SELECT → choose columns
- FROM → choose table
- WHERE → filter rows
- GROUP BY → group data
- HAVING → filter groups
- ORDER BY → sort results
Â
Think of a database like a store.
Each table is like a shelf, and each row is a record.
SQL is how you ask questions about the data.
For example:
- "Show me all products"
- "Show me sales greater than 1000"
- "Which category sells the most?"
SQL helps you answer these questions quickly.
Â
🔹 Practice Queries
Try these queries on your dataset:
🟢 Task 1
SELECT *
FROM superstore;
FROM superstore;
This will show all data
🟢 Task 2
SELECT Category, Sales
FROM superstore;
FROM superstore;
This will show only category and sales
🟢 Task 3
SELECT *
FROM superstore
WHERE Sales > 1000;
FROM superstore
WHERE Sales > 1000;
Filter high sales
🟢 Task 4
SELECT Category, SUM(Sales)
FROM superstore
GROUP BY Category;
FROM superstore
GROUP BY Category;
Total sales by category
Â
🔹 Challenge
Write a query to:
- Show total profit by category
- Only include categories with profit greater than 5000
- Sort the results from highest to lowest
Â
🔹 Why SQL Matters
SQL is one of the most important tools for data analysts.
It allows you to work with large datasets efficiently and extract meaningful insights.
If you understand SQL, you can analyze data directly from databases.