```html
``` Skip to contentAfter completing this lesson, you will be able to:
Organizations collect enormous amounts of data every day, including customer information, product sales, financial transactions, website activity, employee records, and inventory details. This data is usually stored in relational databases rather than spreadsheets because databases provide better security, scalability, and performance.
Structured Query Language (SQL) is the standard language used to communicate with relational databases. Data Analysts use SQL to retrieve, filter, summarize, transform, and analyze data before creating reports and dashboards.
SQL is considered one of the most important technical skills for Data Analysts because nearly every organization stores business data in databases such as MySQL, PostgreSQL, Microsoft SQL Server, Oracle Database, or SQLite.
SQL (Structured Query Language) is a standard programming language used to manage and manipulate data stored in relational databases.
SQL allows users to:
Unlike programming languages such as Python or Java, SQL is specifically designed for working with structured data.
Most organizations store their operational and transactional data inside relational databases. Data Analysts use SQL to access this information and convert raw data into meaningful business insights.
SQL is important because it enables analysts to:
Learning SQL is an essential step toward becoming a successful Data Analyst.
A relational database stores data in tables that are related to one another through common fields called keys.
Each table contains rows and columns, making the data easy to organize, retrieve, and analyze.
Example:
An online shopping company may have separate tables for:
These tables are connected using unique identifiers such as Customer ID or Product ID.
A table is a collection of related data organized into rows and columns.
Example: Customers Table
| Customer_ID | Name | City | Age |
|---|---|---|---|
| 101 | Amit | Delhi | 28 |
| 102 | Priya | Mumbai | 31 |
Each row represents one complete record.
Each column represents one attribute of the data.
Several database management systems support SQL.
| Database | Common Use |
|---|---|
| MySQL | Web Applications |
| PostgreSQL | Enterprise Analytics |
| Microsoft SQL Server | Business Intelligence |
| Oracle Database | Large Enterprise Systems |
| SQLite | Mobile and Desktop Applications |
A basic SQL query generally follows this structure:
SELECT column_name FROM table_name WHERE condition ORDER BY column_name;
Each clause performs a specific task in retrieving and organizing data.
The SELECT statement retrieves data from one or more tables.
It is the most frequently used SQL command in Data Analytics.
SELECT * FROM Customers;
This query returns every column and every row from the Customers table.
SELECT Customer_ID,
Name,
City
FROM Customers;
This query returns only the selected columns.
Aliases make query results easier to understand by assigning meaningful names to columns.
SELECT Customer_ID AS CustomerNumber,
Name AS CustomerName
FROM Customers;
The original database structure remains unchanged while the output becomes more readable.
The WHERE clause filters records based on specified conditions.
Instead of retrieving every record, analysts can focus only on relevant data.
SELECT * FROM Customers WHERE City = 'Delhi';
This query returns only customers located in Delhi.
SELECT * FROM Employees WHERE Salary > 60000;
This query retrieves employees earning more than 60,000.
| Operator | Description |
|---|---|
| = | Equal To |
| > | Greater Than |
| < | Less Than |
| >= | Greater Than or Equal To |
| <= | Less Than or Equal To |
| <> | Not Equal To |
SQL also supports logical operators for combining conditions.
| Operator | Purpose |
|---|---|
| AND | Both conditions must be true. |
| OR | At least one condition must be true. |
| NOT | Reverses a condition. |
SELECT * FROM Customers WHERE City='Delhi' AND Age > 25;
The ORDER BY clause sorts query results in ascending or descending order.
SELECT * FROM Products ORDER BY Price ASC;
SELECT * FROM Products ORDER BY Price DESC;
Sorting makes reports easier to interpret.
The LIMIT clause restricts the number of rows returned by a query.
SELECT * FROM Products LIMIT 10;
This query returns only the first 10 records.
Analysts frequently use LIMIT when exploring large datasets.
The following query combines multiple SQL clauses.
SELECT Product_Name,
Sales_Amount
FROM Sales
WHERE Sales_Amount > 50000
ORDER BY Sales_Amount DESC
LIMIT 5;
This query returns the top five products with sales greater than 50,000.
An e-commerce company stores millions of customer transactions in a MySQL database.
A Data Analyst needs to identify the highest-value customers in Delhi.
The analyst writes the following SQL query:
SELECT Customer_Name,
Total_Purchase
FROM Customers
WHERE City='Delhi'
ORDER BY Total_Purchase DESC
LIMIT 10;
The query instantly retrieves the top ten customers based on total purchases, helping the marketing team identify premium customers for loyalty programs.
Continue to Part 2, where you will learn Aggregate Functions, DISTINCT, GROUP BY, HAVING, SQL Operators, and SQL JOINs with practical business examples.