If I had to start learning data analyst all over again, I'd follow this:
1- Learn SQL:
---- Joins (Inner, Left, Full outer and Self)
---- Aggregate Functions (COUNT, SUM, AVG, MIN, MAX)
---- Group by and Having clause
---- CTE and Subquery
---- Windows Function (Rank, Dense Rank, Row number, Lead, Lag etc)
2- Learn Excel:
---- Mathematical (COUNT, SUM, AVG, MIN, MAX, etc)
---- Logical Functions (IF, AND, OR, NOT)
---- Lookup and Reference (VLookup, INDEX, MATCH etc)
---- Pivot Table, Filters, Slicers
3- Learn BI Tools:
---- Data Integration and ETL (Extract, Transform, Load)
---- Report Generation
---- Data Exploration and Ad-hoc Analysis
---- Dashboard Creation
4- Learn Python (Pandas) Optional:
---- Data Structures, Data Cleaning and Preparation
---- Data Manipulation
---- Merging and Joining Data (Merging and joining DataFrames -similar to SQL joins)
---- Data Visualization (Basic plotting using Matplotlib and Seaborn)
Hope this helps you ๐
1- Learn SQL:
---- Joins (Inner, Left, Full outer and Self)
---- Aggregate Functions (COUNT, SUM, AVG, MIN, MAX)
---- Group by and Having clause
---- CTE and Subquery
---- Windows Function (Rank, Dense Rank, Row number, Lead, Lag etc)
2- Learn Excel:
---- Mathematical (COUNT, SUM, AVG, MIN, MAX, etc)
---- Logical Functions (IF, AND, OR, NOT)
---- Lookup and Reference (VLookup, INDEX, MATCH etc)
---- Pivot Table, Filters, Slicers
3- Learn BI Tools:
---- Data Integration and ETL (Extract, Transform, Load)
---- Report Generation
---- Data Exploration and Ad-hoc Analysis
---- Dashboard Creation
4- Learn Python (Pandas) Optional:
---- Data Structures, Data Cleaning and Preparation
---- Data Manipulation
---- Merging and Joining Data (Merging and joining DataFrames -similar to SQL joins)
---- Data Visualization (Basic plotting using Matplotlib and Seaborn)
Hope this helps you ๐
โค3
๐ฏ SQL Fundamentals Part-1: SELECT Basics
SELECT is the most used SQL command, used to retrieve data from a database.
Think of SQL like asking questions to a database. SELECT = asking what data you want.
โ What is SELECT in SQL?
SELECT statement retrieves data from one or more tables in a database.
๐ Basic Syntax
How SQL executes:
1. Finds table (FROM)
2. Applies filter (WHERE)
3. Returns selected columns (SELECT)
4. Sorts results (ORDER BY)
5. Limits rows (LIMIT)
๐น 1. SELECT All Columns (SELECT *)
Used to retrieve every column from a table.
๐ Returns complete table data.
๐ When to use:
โ Exploring new dataset
โ Checking table structure
โ Quick testing
โ ๏ธ Avoid in production: Slow on large tables, fetches unnecessary data.
๐น 2. SELECT Specific Columns
Best practice โ retrieve only required data.
๐ Returns only selected columns.
๐ก Why important:
โ Faster queries
โ Better performance
โ Cleaner results
๐น 3. FROM Clause (Data Source)
Specifies where data comes from.
๐ SQL reads data from customers table.
๐น 4. WHERE Clause (Filtering Data)
Used to filter rows based on conditions.
Examples:
- Filter by value:
- Filter by text:
๐น 5. ORDER BY (Sorting Results)
Sorts query results.
Examples:
- Ascending:
- Descending:
๐น 6. LIMIT (Control Output Rows)
Restricts number of returned rows.
๐ Returns first 5 records.
โญ SQL Query Execution Order
1. FROM
2. WHERE
3. SELECT
4. ORDER BY
5. LIMIT
๐ง Real-World Example
Business question: "Show top 10 highest paid employees."
๐ Mini Practice Tasks
โ Task 1: Get all records from customers.
โ Task 2: Show only customer name and city.
โ Task 3: Find employees with salary > 40000.
โ Task 4: Show top 3 highest priced products.
Double Tap โฅ๏ธ For Part-2
SELECT is the most used SQL command, used to retrieve data from a database.
Think of SQL like asking questions to a database. SELECT = asking what data you want.
โ What is SELECT in SQL?
SELECT statement retrieves data from one or more tables in a database.
๐ Basic Syntax
SELECT column_name
FROM table_name;
How SQL executes:
1. Finds table (FROM)
2. Applies filter (WHERE)
3. Returns selected columns (SELECT)
4. Sorts results (ORDER BY)
5. Limits rows (LIMIT)
๐น 1. SELECT All Columns (SELECT *)
Used to retrieve every column from a table.
SELECT *
FROM employees;
๐ Returns complete table data.
๐ When to use:
โ Exploring new dataset
โ Checking table structure
โ Quick testing
โ ๏ธ Avoid in production: Slow on large tables, fetches unnecessary data.
๐น 2. SELECT Specific Columns
Best practice โ retrieve only required data.
SELECT name, salary
FROM employees;
๐ Returns only selected columns.
๐ก Why important:
โ Faster queries
โ Better performance
โ Cleaner results
๐น 3. FROM Clause (Data Source)
Specifies where data comes from.
SELECT name
FROM customers;
๐ SQL reads data from customers table.
๐น 4. WHERE Clause (Filtering Data)
Used to filter rows based on conditions.
SELECT column
FROM table
WHERE condition;
Examples:
- Filter by value:
SELECT * FROM employees WHERE salary > 50000;- Filter by text:
SELECT * FROM employees WHERE city = 'Mumbai';๐น 5. ORDER BY (Sorting Results)
Sorts query results.
SELECT column
FROM table
ORDER BY column ASC | DESC;
Examples:
- Ascending:
SELECT name, salary FROM employees ORDER BY salary ASC;- Descending:
SELECT name, salary FROM employees ORDER BY salary DESC;๐น 6. LIMIT (Control Output Rows)
Restricts number of returned rows.
SELECT *
FROM employees
LIMIT 5;
๐ Returns first 5 records.
โญ SQL Query Execution Order
1. FROM
2. WHERE
3. SELECT
4. ORDER BY
5. LIMIT
๐ง Real-World Example
Business question: "Show top 10 highest paid employees."
SELECT name, salary
FROM employees
ORDER BY salary DESC
LIMIT 10;
๐ Mini Practice Tasks
โ Task 1: Get all records from customers.
โ Task 2: Show only customer name and city.
โ Task 3: Find employees with salary > 40000.
โ Task 4: Show top 3 highest priced products.
Double Tap โฅ๏ธ For Part-2
โค14๐ค1
๐ SQL Fundamentals Part-2: Filtering
After learning SELECT basics, the next step is learning how to filter data.
๐ In real-world data analysis, you rarely need full data โ you filter specific rows.
Filtering = extracting only relevant data from a table.
โ What is Filtering in SQL?
Filtering is done using the WHERE clause.
It allows you to:
โ Get specific records
โ Apply conditions
โ Clean data
โ Extract business insights
๐น 1. Comparison Operators
Used to compare values.
Operator Meaning
โข = Equal
โข > Greater than
โข < Less than
โข >= Greater than or equal
โข <= Less than or equal
โข != or <> Not equal
โ Examples
โข Equal to
SELECT * FROM employees WHERE city = 'Pune';
โข Greater than
SELECT * FROM employees WHERE salary > 50000;
โข Not equal
SELECT * FROM employees WHERE department != 'HR';
๐ก Most commonly used in dashboards reporting.
๐น 2. Logical Operators (AND, OR, NOT)
Used to combine multiple conditions.
โ AND โ Both conditions must be true
SELECT * FROM employees WHERE salary > 50000 AND city = 'Mumbai';
๐ Returns employees with: salary > 50000 AND located in Mumbai
โ OR โ Any condition can be true
SELECT * FROM employees WHERE city = 'Delhi' OR city = 'Pune';
๐ Returns employees from either city.
โ NOT โ Reverse condition
SELECT * FROM employees WHERE NOT department = 'Sales';
๐ Excludes Sales department.
๐น 3. BETWEEN (Range Filtering)
Used to filter values within a range.
Syntax
SELECT * FROM table WHERE column BETWEEN value1 AND value2;
โ Example
SELECT * FROM employees WHERE salary BETWEEN 30000 AND 70000;
๐ Includes boundary values.
๐น 4. IN Operator (Multiple Values Shortcut)
Better alternative to multiple OR conditions.
โ Without IN
WHERE city = 'Pune' OR city = 'Delhi' OR city = 'Mumbai'
โ With IN
SELECT * FROM employees WHERE city IN ('Pune','Delhi','Mumbai');
๐ Cleaner and faster.
๐น 5. LIKE โ Pattern Matching
Used for searching text patterns.
โญ Wildcards
Symbol Meaning
โข % Any number of characters
โข _ Single character
โ Starts with "A"
SELECT * FROM customers WHERE name LIKE 'A%';
โ Ends with "n"
WHERE name LIKE '%n';
โ Contains "an"
WHERE name LIKE '%an%';
Used heavily in search features.
๐น 6. NULL Handling (Very Important โญ)
NULL means:
๐ Missing / unknown value
๐ Not zero
๐ Not empty
โ Wrong
WHERE salary = NULL
โ Correct
SELECT * FROM employees WHERE salary IS NULL;
Check non-null values
WHERE salary IS NOT NULL;
๐ก Very common interview question.
โญ Order of Filtering Execution
SQL processes filtering after reading table:
FROM โ WHERE โ SELECT โ ORDER BY โ LIMIT
๐ง Real-World Data Analyst Examples
Q. Find customers from Pune
SELECT * FROM customers WHERE city = 'Pune';
Q. Find high-paying jobs in IT department
SELECT * FROM employees WHERE salary > 80000 AND department = 'IT';
Q. Find names starting with "R"
SELECT * FROM employees WHERE name LIKE 'R%';
Used daily in business analytics.
๐ Mini Practice Tasks
โ Q1
Find employees whose salary is greater than 60000.
โ Q2
Find customers from Pune or Mumbai.
โ Q3
Find products priced between 100 and 500.
โ Q4
Find employees whose name starts with "S".
โ Q5
Find records where email is missing (NULL).
โ Double Tap โฅ๏ธ For More
After learning SELECT basics, the next step is learning how to filter data.
๐ In real-world data analysis, you rarely need full data โ you filter specific rows.
Filtering = extracting only relevant data from a table.
โ What is Filtering in SQL?
Filtering is done using the WHERE clause.
It allows you to:
โ Get specific records
โ Apply conditions
โ Clean data
โ Extract business insights
๐น 1. Comparison Operators
Used to compare values.
Operator Meaning
โข = Equal
โข > Greater than
โข < Less than
โข >= Greater than or equal
โข <= Less than or equal
โข != or <> Not equal
โ Examples
โข Equal to
SELECT * FROM employees WHERE city = 'Pune';
โข Greater than
SELECT * FROM employees WHERE salary > 50000;
โข Not equal
SELECT * FROM employees WHERE department != 'HR';
๐ก Most commonly used in dashboards reporting.
๐น 2. Logical Operators (AND, OR, NOT)
Used to combine multiple conditions.
โ AND โ Both conditions must be true
SELECT * FROM employees WHERE salary > 50000 AND city = 'Mumbai';
๐ Returns employees with: salary > 50000 AND located in Mumbai
โ OR โ Any condition can be true
SELECT * FROM employees WHERE city = 'Delhi' OR city = 'Pune';
๐ Returns employees from either city.
โ NOT โ Reverse condition
SELECT * FROM employees WHERE NOT department = 'Sales';
๐ Excludes Sales department.
๐น 3. BETWEEN (Range Filtering)
Used to filter values within a range.
Syntax
SELECT * FROM table WHERE column BETWEEN value1 AND value2;
โ Example
SELECT * FROM employees WHERE salary BETWEEN 30000 AND 70000;
๐ Includes boundary values.
๐น 4. IN Operator (Multiple Values Shortcut)
Better alternative to multiple OR conditions.
โ Without IN
WHERE city = 'Pune' OR city = 'Delhi' OR city = 'Mumbai'
โ With IN
SELECT * FROM employees WHERE city IN ('Pune','Delhi','Mumbai');
๐ Cleaner and faster.
๐น 5. LIKE โ Pattern Matching
Used for searching text patterns.
โญ Wildcards
Symbol Meaning
โข % Any number of characters
โข _ Single character
โ Starts with "A"
SELECT * FROM customers WHERE name LIKE 'A%';
โ Ends with "n"
WHERE name LIKE '%n';
โ Contains "an"
WHERE name LIKE '%an%';
Used heavily in search features.
๐น 6. NULL Handling (Very Important โญ)
NULL means:
๐ Missing / unknown value
๐ Not zero
๐ Not empty
โ Wrong
WHERE salary = NULL
โ Correct
SELECT * FROM employees WHERE salary IS NULL;
Check non-null values
WHERE salary IS NOT NULL;
๐ก Very common interview question.
โญ Order of Filtering Execution
SQL processes filtering after reading table:
FROM โ WHERE โ SELECT โ ORDER BY โ LIMIT
๐ง Real-World Data Analyst Examples
Q. Find customers from Pune
SELECT * FROM customers WHERE city = 'Pune';
Q. Find high-paying jobs in IT department
SELECT * FROM employees WHERE salary > 80000 AND department = 'IT';
Q. Find names starting with "R"
SELECT * FROM employees WHERE name LIKE 'R%';
Used daily in business analytics.
๐ Mini Practice Tasks
โ Q1
Find employees whose salary is greater than 60000.
โ Q2
Find customers from Pune or Mumbai.
โ Q3
Find products priced between 100 and 500.
โ Q4
Find employees whose name starts with "S".
โ Q5
Find records where email is missing (NULL).
โ Double Tap โฅ๏ธ For More
โค8
SQL is easy to learn, but difficult to master.
Here are 5 hacks to level up your SQL ๐
1. Know complex joins
2. Master Window functions
3. Explore alternative solutions
4. Master query optimization
5. Get familiar with ETL
โโโ
๐๐ต๐ธ, ๐ต๐ฉ๐ฆ๐ณ๐ฆ ๐ข๐ณ๐ฆ ๐ฑ๐ณ๐ข๐ค๐ต๐ช๐ค๐ฆ ๐ฑ๐ณ๐ฐ๐ฃ๐ญ๐ฆ๐ฎ๐ด ๐ช๐ฏ ๐ต๐ฉ๐ฆ ๐ค๐ข๐ณ๐ฐ๐ถ๐ด๐ฆ๐ญ.
๐ญ/ ๐๐ป๐ผ๐ ๐ฐ๐ผ๐บ๐ฝ๐น๐ฒ๐ ๐ท๐ผ๐ถ๐ป๐
LEFT JOIN, RIGHT JOIN, INNER JOIN, OUTER JOIN โ these are easy.
But SQL gets really powerful, when you know
โณ Anti Joins
โณ Self Joins
โณ Cartesian Joins
โณ Multi-Table Joins
๐ฎ/ ๐ ๐ฎ๐๐๐ฒ๐ฟ ๐ช๐ถ๐ป๐ฑ๐ผ๐ ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป๐
Window functions = flexible, effective, and essential.
They give you Python-like versatility in SQL. ๐๐ถ๐ฑ๐ฆ๐ณ ๐ค๐ฐ๐ฐ๐ญ.
๐ฏ/ ๐๐ ๐ฝ๐น๐ผ๐ฟ๐ฒ ๐ฎ๐น๐๐ฒ๐ฟ๐ป๐ฎ๐๐ถ๐๐ฒ ๐๐ผ๐น๐๐๐ถ๐ผ๐ป๐
In SQL, thereโs rarely one โrightโ way to solve a problem.
By exploring alternative approaches, you develop flexibility in thinking AND learn about trade-offs.
๐ฐ/ ๐ ๐ฎ๐๐๐ฒ๐ฟ ๐พ๐๐ฒ๐ฟ๐ ๐ผ๐ฝ๐๐ถ๐บ๐ถ๐๐ฎ๐๐ถ๐ผ๐ป
Inefficient queries overload systems, cost money and waste time.
3 (super quick) tips on optimizing queries:
1. Use indexes effectively
2. Analyze execution plans
3. Reduce unnecessary operations
๐ฑ/ ๐๐ฒ๐ ๐ณ๐ฎ๐บ๐ถ๐น๐ถ๐ฎ๐ฟ ๐๐ถ๐๐ต ๐๐ง๐
ETL is the backbone of moving and preparing data.
โณ Extract: Pull data from various sources
โณ Transform: Clean, filter, and reformat the data
โณ Load: Store the cleaned data in a data warehouse
Here you can find essential SQL Interview Resources๐
https://t.iss.one/mysqldata
Like this post if you need more ๐โค๏ธ
Hope it helps :)
Here are 5 hacks to level up your SQL ๐
1. Know complex joins
2. Master Window functions
3. Explore alternative solutions
4. Master query optimization
5. Get familiar with ETL
โโโ
๐๐ต๐ธ, ๐ต๐ฉ๐ฆ๐ณ๐ฆ ๐ข๐ณ๐ฆ ๐ฑ๐ณ๐ข๐ค๐ต๐ช๐ค๐ฆ ๐ฑ๐ณ๐ฐ๐ฃ๐ญ๐ฆ๐ฎ๐ด ๐ช๐ฏ ๐ต๐ฉ๐ฆ ๐ค๐ข๐ณ๐ฐ๐ถ๐ด๐ฆ๐ญ.
๐ญ/ ๐๐ป๐ผ๐ ๐ฐ๐ผ๐บ๐ฝ๐น๐ฒ๐ ๐ท๐ผ๐ถ๐ป๐
LEFT JOIN, RIGHT JOIN, INNER JOIN, OUTER JOIN โ these are easy.
But SQL gets really powerful, when you know
โณ Anti Joins
โณ Self Joins
โณ Cartesian Joins
โณ Multi-Table Joins
๐ฎ/ ๐ ๐ฎ๐๐๐ฒ๐ฟ ๐ช๐ถ๐ป๐ฑ๐ผ๐ ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป๐
Window functions = flexible, effective, and essential.
They give you Python-like versatility in SQL. ๐๐ถ๐ฑ๐ฆ๐ณ ๐ค๐ฐ๐ฐ๐ญ.
๐ฏ/ ๐๐ ๐ฝ๐น๐ผ๐ฟ๐ฒ ๐ฎ๐น๐๐ฒ๐ฟ๐ป๐ฎ๐๐ถ๐๐ฒ ๐๐ผ๐น๐๐๐ถ๐ผ๐ป๐
In SQL, thereโs rarely one โrightโ way to solve a problem.
By exploring alternative approaches, you develop flexibility in thinking AND learn about trade-offs.
๐ฐ/ ๐ ๐ฎ๐๐๐ฒ๐ฟ ๐พ๐๐ฒ๐ฟ๐ ๐ผ๐ฝ๐๐ถ๐บ๐ถ๐๐ฎ๐๐ถ๐ผ๐ป
Inefficient queries overload systems, cost money and waste time.
3 (super quick) tips on optimizing queries:
1. Use indexes effectively
2. Analyze execution plans
3. Reduce unnecessary operations
๐ฑ/ ๐๐ฒ๐ ๐ณ๐ฎ๐บ๐ถ๐น๐ถ๐ฎ๐ฟ ๐๐ถ๐๐ต ๐๐ง๐
ETL is the backbone of moving and preparing data.
โณ Extract: Pull data from various sources
โณ Transform: Clean, filter, and reformat the data
โณ Load: Store the cleaned data in a data warehouse
Here you can find essential SQL Interview Resources๐
https://t.iss.one/mysqldata
Like this post if you need more ๐โค๏ธ
Hope it helps :)
Telegram
SQL For Data Analytics
This channel covers everything you need to learn SQL for data science, data analyst, data engineer and business analyst roles.
โค5
Here are some essential SQL tips for beginners ๐๐
โ Primary Key = Unique Key + Not Null constraint
โ To perform case insensitive search use UPPER() function ex. UPPER(customer_name) LIKE โA%Aโ
โ LIKE operator is for string data type
โ COUNT(*), COUNT(1), COUNT(0) all are same
โ All aggregate functions ignore the NULL values
โ Aggregate functions MIN, MAX, SUM, AVG, COUNT are for int data type whereas STRING_AGG is for string data type
โ For row level filtration use WHERE and aggregate level filtration use HAVING
โ UNION ALL will include duplicates where as UNION excludes duplicates
โ If the results will not have any duplicates, use UNION ALL instead of UNION
โ We have to alias the subquery if we are using the columns in the outer select query
โ Subqueries can be used as output with NOT IN condition.
โ CTEs look better than subqueries. Performance wise both are same.
โ When joining two tables , if one table has only one value then we can use 1=1 as a condition to join the tables. This will be considered as CROSS JOIN.
โ Window functions work at ROW level.
โ The difference between RANK() and DENSE_RANK() is that RANK() skips the rank if the values are the same.
โ EXISTS works on true/false conditions. If the query returns at least one value, the condition is TRUE. All the records corresponding to the conditions are returned.
Like for more ๐๐
โ Primary Key = Unique Key + Not Null constraint
โ To perform case insensitive search use UPPER() function ex. UPPER(customer_name) LIKE โA%Aโ
โ LIKE operator is for string data type
โ COUNT(*), COUNT(1), COUNT(0) all are same
โ All aggregate functions ignore the NULL values
โ Aggregate functions MIN, MAX, SUM, AVG, COUNT are for int data type whereas STRING_AGG is for string data type
โ For row level filtration use WHERE and aggregate level filtration use HAVING
โ UNION ALL will include duplicates where as UNION excludes duplicates
โ If the results will not have any duplicates, use UNION ALL instead of UNION
โ We have to alias the subquery if we are using the columns in the outer select query
โ Subqueries can be used as output with NOT IN condition.
โ CTEs look better than subqueries. Performance wise both are same.
โ When joining two tables , if one table has only one value then we can use 1=1 as a condition to join the tables. This will be considered as CROSS JOIN.
โ Window functions work at ROW level.
โ The difference between RANK() and DENSE_RANK() is that RANK() skips the rank if the values are the same.
โ EXISTS works on true/false conditions. If the query returns at least one value, the condition is TRUE. All the records corresponding to the conditions are returned.
Like for more ๐๐
โค4
๐ SQL Fundamentals Part-4: JOINS
In real databases, data is stored in multiple tables, not one big table. JOINS allow you to combine data from different tables.
Example:
Customers Table
customer_id | name
1 | Rahul
2 | Priya
Orders Table
order_id | customer_id | amount
101 | 1 | 500
102 | 2 | 300
To see customer name + order amount, we must use JOIN.
Basic JOIN Syntax
SELECT columns
FROM table1
JOIN table2
ON table1.column = table2.column;
ON defines the relationship between tables.
1๏ธโฃ INNER JOIN
Returns only matching records from both tables.
SELECT customers.name, orders.amount
FROM customers
INNER JOIN orders
ON customers.customer_id = orders.customer_id;
Result:
name | amount
Rahul | 500
Priya | 300
๐ If a customer has no order, they will not appear.
2๏ธโฃ LEFT JOIN (Very Common โญ)
Returns: All rows from left table, Matching rows from right table, If no match โ NULL
SELECT customers.name, orders.amount
FROM customers
LEFT JOIN orders
ON customers.customer_id = orders.customer_id;
Result:
name | amount
Rahul | 500
Priya | 300
Amit | NULL
๐ Amit has no order.
3๏ธโฃ RIGHT JOIN
Opposite of LEFT JOIN. Returns: All rows from right table, Matching rows from left table
SELECT customers.name, orders.amount
FROM customers
RIGHT JOIN orders
ON customers.customer_id = orders.customer_id;
Used less frequently in analytics.
4๏ธโฃ FULL JOIN
Returns: All records from both tables, If no match โ NULL
SELECT customers.name, orders.amount
FROM customers
FULL JOIN orders
ON customers.customer_id = orders.customer_id;
5๏ธโฃ SELF JOIN
A table joins with itself. Used when rows relate to other rows in the same table.
SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m
ON e.manager_id = m.employee_id;
JOIN Visual Understanding
โข INNER JOIN: Only matching rows
โข LEFT JOIN: All left + matching right
โข RIGHT JOIN: All right + matching left
โข FULL JOIN: All rows from both
โข SELF JOIN: Table joined with itself
Real Data Analyst Examples
-- Customer order report
SELECT c.name, o.amount
FROM customers c
JOIN orders o
ON c.customer_id = o.customer_id;
-- Products with category
SELECT p.product_name, c.category
FROM products p
JOIN categories c
ON p.category_id = c.category_id;
-- Sales by region
SELECT r.region_name, SUM(s.amount)
FROM sales s
JOIN regions r
ON s.region_id = r.region_id
GROUP BY r.region_name;
Used daily in Power BI dashboards, analytics queries, and reports.
Mini Practice Tasks
1. Show customer names with their order amount.
2. Show all customers even if they have no orders.
3. Show employees with their manager names.
4. Show products with their category name.
Common Interview Questions
โ Difference between INNER JOIN and LEFT JOIN
โ When to use SELF JOIN
โ Why LEFT JOIN is used in analytics
โ Difference between JOIN and UNION
โ Join execution order
Double Tap โฅ๏ธ For More
In real databases, data is stored in multiple tables, not one big table. JOINS allow you to combine data from different tables.
Example:
Customers Table
customer_id | name
1 | Rahul
2 | Priya
Orders Table
order_id | customer_id | amount
101 | 1 | 500
102 | 2 | 300
To see customer name + order amount, we must use JOIN.
Basic JOIN Syntax
SELECT columns
FROM table1
JOIN table2
ON table1.column = table2.column;
ON defines the relationship between tables.
1๏ธโฃ INNER JOIN
Returns only matching records from both tables.
SELECT customers.name, orders.amount
FROM customers
INNER JOIN orders
ON customers.customer_id = orders.customer_id;
Result:
name | amount
Rahul | 500
Priya | 300
๐ If a customer has no order, they will not appear.
2๏ธโฃ LEFT JOIN (Very Common โญ)
Returns: All rows from left table, Matching rows from right table, If no match โ NULL
SELECT customers.name, orders.amount
FROM customers
LEFT JOIN orders
ON customers.customer_id = orders.customer_id;
Result:
name | amount
Rahul | 500
Priya | 300
Amit | NULL
๐ Amit has no order.
3๏ธโฃ RIGHT JOIN
Opposite of LEFT JOIN. Returns: All rows from right table, Matching rows from left table
SELECT customers.name, orders.amount
FROM customers
RIGHT JOIN orders
ON customers.customer_id = orders.customer_id;
Used less frequently in analytics.
4๏ธโฃ FULL JOIN
Returns: All records from both tables, If no match โ NULL
SELECT customers.name, orders.amount
FROM customers
FULL JOIN orders
ON customers.customer_id = orders.customer_id;
5๏ธโฃ SELF JOIN
A table joins with itself. Used when rows relate to other rows in the same table.
SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m
ON e.manager_id = m.employee_id;
JOIN Visual Understanding
โข INNER JOIN: Only matching rows
โข LEFT JOIN: All left + matching right
โข RIGHT JOIN: All right + matching left
โข FULL JOIN: All rows from both
โข SELF JOIN: Table joined with itself
Real Data Analyst Examples
-- Customer order report
SELECT c.name, o.amount
FROM customers c
JOIN orders o
ON c.customer_id = o.customer_id;
-- Products with category
SELECT p.product_name, c.category
FROM products p
JOIN categories c
ON p.category_id = c.category_id;
-- Sales by region
SELECT r.region_name, SUM(s.amount)
FROM sales s
JOIN regions r
ON s.region_id = r.region_id
GROUP BY r.region_name;
Used daily in Power BI dashboards, analytics queries, and reports.
Mini Practice Tasks
1. Show customer names with their order amount.
2. Show all customers even if they have no orders.
3. Show employees with their manager names.
4. Show products with their category name.
Common Interview Questions
โ Difference between INNER JOIN and LEFT JOIN
โ When to use SELF JOIN
โ Why LEFT JOIN is used in analytics
โ Difference between JOIN and UNION
โ Join execution order
Double Tap โฅ๏ธ For More
โค12
SQL Detailed Roadmap
|
| | |-- Fundamentals
| |-- Introduction to Databases
| | |-- What SQL does
| | |-- Relational model
| | |-- Tables, rows, columns
| |-- Keys and Constraints
| | |-- Primary keys
| | |-- Foreign keys
| | |-- Unique and check constraints
| |-- Normalization
| | |-- 1NF, 2NF, 3NF
| | |-- ER diagrams
| | |-- Core SQL
| |-- SQL Basics
| | |-- SELECT, WHERE, ORDER BY
| | |-- GROUP BY and HAVING
| | |-- JOINS: INNER, LEFT, RIGHT, FULL
| |-- Intermediate SQL
| | |-- Subqueries
| | |-- CTEs
| | |-- CASE statements
| | |-- Aggregations
| |-- Advanced SQL
| | |-- Window functions
| | |-- Analytical functions
| | |-- Ranking, moving averages, lag and lead
| | |-- UNION, INTERSECT, EXCEPT
| | |-- Data Management
| |-- Data Types
| | |-- Numeric, text, date, JSON
| |-- Indexes
| | |-- B tree and hash indexes
| | |-- When to create indexes
| |-- Transactions
| | |-- ACID properties
| |-- Views
| | |-- Standard views
| | |-- Materialized views
| | |-- Database Design
| |-- Schema Design
| | |-- Star schema
| | |-- Snowflake schema
| |-- Fact and Dimension Tables
| |-- Constraints for clean data
| | |-- Performance Tuning
| |-- Query Optimization
| | |-- Execution plans
| | |-- Index usage
| | |-- Reducing scans
| |-- Partitioning
| | |-- Horizontal partitioning
| | |-- Sharding basics
| | |-- SQL for Analytics
| |-- KPI calculations
| |-- Cohort analysis
| |-- Funnel analysis
| |-- Churn and retention tables
| |-- Time based aggregations
| |-- Window functions for metrics
| | |-- SQL for Data Engineering
| |-- ETL Workflows
| | |-- Staging tables
| | |-- Transformations
| | |-- Incremental loads
| |-- Data Warehousing
| | |-- Snowflake
| | |-- Redshift
| | |-- BigQuery
| |-- dbt Basics
| | |-- Models
| | |-- Tests
| | |-- Lineage
| | |-- Tools and Platforms
| |-- PostgreSQL
| |-- MySQL
| |-- SQL Server
| |-- Oracle
| |-- SQLite
| |-- Cloud SQL
| |-- BigQuery UI
| |-- Snowflake Worksheets
| | |-- Projects
| |-- Build a sales reporting system
| |-- Create a star schema from raw CSV files
| |-- Design a customer segmentation query
| |-- Build a churn dashboard dataset
| |-- Optimize slow queries in a sample DB
| |-- Create an analytics pipeline with dbt
| | |-- Soft Skills and Career Prep
| |-- SQL interview patterns
| |-- Joins practice
| |-- Window function drills
| |-- Query writing speed
| |-- Git and GitHub
| |-- Data storytelling
| | |-- Bonus Topics
| |-- NoSQL intro
| |-- Working with JSON fields
| |-- Spatial SQL
| |-- Time series tables
| |-- CDC concepts
| |-- Real time analytics
| | |-- Community and Growth
| |-- LeetCode SQL
| |-- Kaggle datasets with SQL
| |-- GitHub projects
| |-- LinkedIn posts
| |-- Open source contributions
Free Resources to learn SQL
โข W3Schools SQL
https://www.w3schools.com/sql/
โข SQL Programming
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
โข SQL Notes
https://whatsapp.com/channel/0029Vb6hJmM9hXFCWNtQX944
โข Mode Analytics SQL tutorials
https://mode.com/sql-tutorial/
โข Data Analytics Resources
https://t.iss.one/sqlspecialist
โข HackerRank SQL practice
https://www.hackerrank.com/domains/sql
โข LeetCode SQL problems
https://leetcode.com/problemset/database/
โข Data Engineering Resources
https://whatsapp.com/channel/0029Vaovs0ZKbYMKXvKRYi3C
โข Khan Academy SQL basics
https://www.khanacademy.org/computing/computer-programming/sql
โข PostgreSQL official docs
https://www.postgresql.org/docs/
โข MySQL official docs
https://dev.mysql.com/doc/
โข NoSQL Resources
https://whatsapp.com/channel/0029VaxA2hTHgZWe5FpFjm3p
Double Tap โค๏ธ For More
|
| | |-- Fundamentals
| |-- Introduction to Databases
| | |-- What SQL does
| | |-- Relational model
| | |-- Tables, rows, columns
| |-- Keys and Constraints
| | |-- Primary keys
| | |-- Foreign keys
| | |-- Unique and check constraints
| |-- Normalization
| | |-- 1NF, 2NF, 3NF
| | |-- ER diagrams
| | |-- Core SQL
| |-- SQL Basics
| | |-- SELECT, WHERE, ORDER BY
| | |-- GROUP BY and HAVING
| | |-- JOINS: INNER, LEFT, RIGHT, FULL
| |-- Intermediate SQL
| | |-- Subqueries
| | |-- CTEs
| | |-- CASE statements
| | |-- Aggregations
| |-- Advanced SQL
| | |-- Window functions
| | |-- Analytical functions
| | |-- Ranking, moving averages, lag and lead
| | |-- UNION, INTERSECT, EXCEPT
| | |-- Data Management
| |-- Data Types
| | |-- Numeric, text, date, JSON
| |-- Indexes
| | |-- B tree and hash indexes
| | |-- When to create indexes
| |-- Transactions
| | |-- ACID properties
| |-- Views
| | |-- Standard views
| | |-- Materialized views
| | |-- Database Design
| |-- Schema Design
| | |-- Star schema
| | |-- Snowflake schema
| |-- Fact and Dimension Tables
| |-- Constraints for clean data
| | |-- Performance Tuning
| |-- Query Optimization
| | |-- Execution plans
| | |-- Index usage
| | |-- Reducing scans
| |-- Partitioning
| | |-- Horizontal partitioning
| | |-- Sharding basics
| | |-- SQL for Analytics
| |-- KPI calculations
| |-- Cohort analysis
| |-- Funnel analysis
| |-- Churn and retention tables
| |-- Time based aggregations
| |-- Window functions for metrics
| | |-- SQL for Data Engineering
| |-- ETL Workflows
| | |-- Staging tables
| | |-- Transformations
| | |-- Incremental loads
| |-- Data Warehousing
| | |-- Snowflake
| | |-- Redshift
| | |-- BigQuery
| |-- dbt Basics
| | |-- Models
| | |-- Tests
| | |-- Lineage
| | |-- Tools and Platforms
| |-- PostgreSQL
| |-- MySQL
| |-- SQL Server
| |-- Oracle
| |-- SQLite
| |-- Cloud SQL
| |-- BigQuery UI
| |-- Snowflake Worksheets
| | |-- Projects
| |-- Build a sales reporting system
| |-- Create a star schema from raw CSV files
| |-- Design a customer segmentation query
| |-- Build a churn dashboard dataset
| |-- Optimize slow queries in a sample DB
| |-- Create an analytics pipeline with dbt
| | |-- Soft Skills and Career Prep
| |-- SQL interview patterns
| |-- Joins practice
| |-- Window function drills
| |-- Query writing speed
| |-- Git and GitHub
| |-- Data storytelling
| | |-- Bonus Topics
| |-- NoSQL intro
| |-- Working with JSON fields
| |-- Spatial SQL
| |-- Time series tables
| |-- CDC concepts
| |-- Real time analytics
| | |-- Community and Growth
| |-- LeetCode SQL
| |-- Kaggle datasets with SQL
| |-- GitHub projects
| |-- LinkedIn posts
| |-- Open source contributions
Free Resources to learn SQL
โข W3Schools SQL
https://www.w3schools.com/sql/
โข SQL Programming
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
โข SQL Notes
https://whatsapp.com/channel/0029Vb6hJmM9hXFCWNtQX944
โข Mode Analytics SQL tutorials
https://mode.com/sql-tutorial/
โข Data Analytics Resources
https://t.iss.one/sqlspecialist
โข HackerRank SQL practice
https://www.hackerrank.com/domains/sql
โข LeetCode SQL problems
https://leetcode.com/problemset/database/
โข Data Engineering Resources
https://whatsapp.com/channel/0029Vaovs0ZKbYMKXvKRYi3C
โข Khan Academy SQL basics
https://www.khanacademy.org/computing/computer-programming/sql
โข PostgreSQL official docs
https://www.postgresql.org/docs/
โข MySQL official docs
https://dev.mysql.com/doc/
โข NoSQL Resources
https://whatsapp.com/channel/0029VaxA2hTHgZWe5FpFjm3p
Double Tap โค๏ธ For More
โค5
โก Subqueries CTEs
After mastering JOINS, the next important concept is Subqueries and CTEs. These are used when queries become complex and you need intermediate results.
๐ Very common in data analyst interviews and real analytics queries.
๐น 1๏ธโฃ What is a Subquery?
A subquery is a query inside another SQL query. It is executed first, and its result is used by the main query.
๐ฏ Basic Syntax
๐ง Example 1 โ Find Employees with Highest Salary
Explanation:
1๏ธโฃ Inner query finds maximum salary
2๏ธโฃ Outer query finds employee with that salary
๐น 2๏ธโฃ Subquery in WHERE Clause
Most common use.
Example โ Employees earning more than average salary
Used heavily in analytics queries.
๐น 3๏ธโฃ Subquery in FROM Clause
Also called Derived Table.
Used when intermediate results are required.
๐น 4๏ธโฃ EXISTS / NOT EXISTS
Used to check if a record exists in another table.
Example โ Customers who placed orders
๐ Returns customers with orders.
Example โ Customers with no orders
โญ 5๏ธโฃ Common Table Expressions (CTEs)
CTEs improve query readability and structure. Defined using WITH clause.
Basic Syntax
๐ง Example โ Average Salary by Department
๐น 6๏ธโฃ Multiple CTEs
You can chain multiple CTEs.
Used often in complex analytics queries.
๐ง Real Analyst Examples
Customers with above average purchases
Complex analytics often uses subqueries or CTEs.
๐ Mini Practice Tasks
๐ฏ Task 1 โ Find employees earning more than average salary
โ Solution
๐ก Explanation: Subquery calculates average salary, Outer query filters employees above average.
๐ฏ Task 2 โ Find customers who placed orders
โ Solution (Using EXISTS โญ)
๐ก Explanation: Checks if an order exists for the customer.
๐ฏ Task 3 โ Find departments with salary greater than company average
โ Solution
๐ก Explanation: Subquery finds company average salary, HAVING filters departments above that average.
๐ฏ Task 4 โ Use a CTE to calculate total sales per customer
โ Solution
๐ก Explanation: CTE calculates total sales for each customer, Main query retrieves the result.
Double Tap โฅ๏ธ For More
After mastering JOINS, the next important concept is Subqueries and CTEs. These are used when queries become complex and you need intermediate results.
๐ Very common in data analyst interviews and real analytics queries.
๐น 1๏ธโฃ What is a Subquery?
A subquery is a query inside another SQL query. It is executed first, and its result is used by the main query.
๐ฏ Basic Syntax
SELECT column
FROM table
WHERE column = (SELECT column FROM table);
๐ง Example 1 โ Find Employees with Highest Salary
SELECT name, salary
FROM employees
WHERE salary = (SELECT MAX(salary) FROM employees);
Explanation:
1๏ธโฃ Inner query finds maximum salary
2๏ธโฃ Outer query finds employee with that salary
๐น 2๏ธโฃ Subquery in WHERE Clause
Most common use.
Example โ Employees earning more than average salary
SELECT name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
Used heavily in analytics queries.
๐น 3๏ธโฃ Subquery in FROM Clause
Also called Derived Table.
SELECT department, AVG(avg_salary)
FROM (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
) AS dept_salary
GROUP BY department;
Used when intermediate results are required.
๐น 4๏ธโฃ EXISTS / NOT EXISTS
Used to check if a record exists in another table.
Example โ Customers who placed orders
SELECT name
FROM customers c
WHERE EXISTS (
SELECT 1
FROM orders o
WHERE c.customer_id = o.customer_id
);
๐ Returns customers with orders.
Example โ Customers with no orders
SELECT name
FROM customers c
WHERE NOT EXISTS (
SELECT 1
FROM orders o
WHERE c.customer_id = o.customer_id
);
โญ 5๏ธโฃ Common Table Expressions (CTEs)
CTEs improve query readability and structure. Defined using WITH clause.
Basic Syntax
WITH cte_name AS (
SELECT column
FROM table
)
SELECT *
FROM cte_name;
๐ง Example โ Average Salary by Department
WITH dept_avg AS (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
)
SELECT *
FROM dept_avg;
๐น 6๏ธโฃ Multiple CTEs
You can chain multiple CTEs.
WITH total_sales AS (
SELECT customer_id, SUM(amount) AS total
FROM orders
GROUP BY customer_id
),
top_customers AS (
SELECT *
FROM total_sales
WHERE total > 1000
)
SELECT *
FROM top_customers;
Used often in complex analytics queries.
๐ง Real Analyst Examples
Customers with above average purchases
SELECT customer_id
FROM orders
GROUP BY customer_id
HAVING SUM(amount) > (
SELECT AVG(total)
FROM (
SELECT SUM(amount) AS total
FROM orders
GROUP BY customer_id
) AS totals
);
Complex analytics often uses subqueries or CTEs.
๐ Mini Practice Tasks
๐ฏ Task 1 โ Find employees earning more than average salary
โ Solution
SELECT name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
๐ก Explanation: Subquery calculates average salary, Outer query filters employees above average.
๐ฏ Task 2 โ Find customers who placed orders
โ Solution (Using EXISTS โญ)
SELECT name
FROM customers c
WHERE EXISTS (
SELECT 1
FROM orders o
WHERE c.customer_id = o.customer_id
);
๐ก Explanation: Checks if an order exists for the customer.
๐ฏ Task 3 โ Find departments with salary greater than company average
โ Solution
SELECT department, AVG(salary)
FROM employees
GROUP BY department
HAVING AVG(salary) > (SELECT AVG(salary) FROM employees);
๐ก Explanation: Subquery finds company average salary, HAVING filters departments above that average.
๐ฏ Task 4 โ Use a CTE to calculate total sales per customer
โ Solution
WITH customer_sales AS (
SELECT customer_id, SUM(amount) AS total_sales
FROM orders
GROUP BY customer_id
)
SELECT * FROM customer_sales;
๐ก Explanation: CTE calculates total sales for each customer, Main query retrieves the result.
Double Tap โฅ๏ธ For More
โค9
What will this query return?
SELECT name FROM employees WHERE salary > (SELECT salary FROM employees);
SELECT name FROM employees WHERE salary > (SELECT salary FROM employees);
Anonymous Quiz
40%
A) Employees with highest salary
44%
B) Error: Subquery returns multiple rows
14%
C) All employees
3%
D) Only first employee
What will this query output?
SELECT * FROM employees WHERE department_id IN ( SELECT department_id FROM departments );
SELECT * FROM employees WHERE department_id IN ( SELECT department_id FROM departments );
Anonymous Quiz
76%
A) Employees with departments listed in the departments table
13%
B) All employees
6%
C) No employees
5%
D) Only department names
What is the output of this query?
WITH numbers AS ( SELECT 10 AS value UNION SELECT 20 ) SELECT SUM(value) FROM numbers;
WITH numbers AS ( SELECT 10 AS value UNION SELECT 20 ) SELECT SUM(value) FROM numbers;
Anonymous Quiz
11%
A) 10
18%
B) 20
46%
C) 30
24%
D) Error
What will this query return?
SELECT name FROM customers WHERE NOT EXISTS ( SELECT * FROM orders WHERE customers.customer_id = orders.customer_id );
SELECT name FROM customers WHERE NOT EXISTS ( SELECT * FROM orders WHERE customers.customer_id = orders.customer_id );
Anonymous Quiz
23%
A) Customers who placed orders
67%
B) Customers without orders
7%
C) All customers
3%
D) Only order details
โค1
๐ง SQL Interview Question (ModerateโTricky & Duplicate Transaction Detection)
๐
transactions(transaction_id, user_id, transaction_date, amount)
โ Ques :
๐ Find users who made multiple transactions with the same amount consecutively.
๐งฉ How Interviewers Expect You to Think
โข Sort transactions chronologically for each user
โข Compare the current transaction amount with the previous one
โข Use a window function to detect consecutive duplicates
๐ก SQL Solution
SELECT
user_id,
transaction_date,
amount
FROM (
SELECT
user_id,
transaction_date,
amount,
LAG(amount) OVER (
PARTITION BY user_id
ORDER BY transaction_date
) AS prev_amount
FROM transactions
) t
WHERE amount = prev_amount;
๐ฅ Why This Question Is Powerful
โข Tests understanding of LAG() for row comparison
โข Evaluates ability to identify patterns in sequential data
โข Reflects real-world use cases like detecting suspicious or duplicate transactions
โค๏ธ React if you want more tricky real interview-level SQL questions ๐
๐
transactions(transaction_id, user_id, transaction_date, amount)
โ Ques :
๐ Find users who made multiple transactions with the same amount consecutively.
๐งฉ How Interviewers Expect You to Think
โข Sort transactions chronologically for each user
โข Compare the current transaction amount with the previous one
โข Use a window function to detect consecutive duplicates
๐ก SQL Solution
SELECT
user_id,
transaction_date,
amount
FROM (
SELECT
user_id,
transaction_date,
amount,
LAG(amount) OVER (
PARTITION BY user_id
ORDER BY transaction_date
) AS prev_amount
FROM transactions
) t
WHERE amount = prev_amount;
๐ฅ Why This Question Is Powerful
โข Tests understanding of LAG() for row comparison
โข Evaluates ability to identify patterns in sequential data
โข Reflects real-world use cases like detecting suspicious or duplicate transactions
โค๏ธ React if you want more tricky real interview-level SQL questions ๐
โค11
๐ Window Functions โญ
Window functions are one of the most powerful SQL features used in data analytics, reporting, and advanced SQL interviews.
๐ They allow you to perform calculations across rows without collapsing them like GROUP BY.
In simple words:
GROUP BY โ reduces rows
Window Functions โ keep rows but add calculated values
๐ง Basic Syntax of Window Functions
- OVER() โ defines the window
- PARTITION BY โ splits data into groups
- ORDER BY โ defines calculation order
๐น 1๏ธโฃ ROW_NUMBER()
Assigns a unique sequential number to rows.
name | salary | rank
Rahul | 90000 | 1
Priya | 85000 | 2
Amit | 85000 | 3
๐ Even if salaries are same, numbers stay unique.
๐น 2๏ธโฃ RANK()
Assigns rank but skips numbers when ties occur.
name | salary | rank
Rahul | 90000 | 1
Priya | 85000 | 2
Amit | 85000 | 2
Neha | 80000 | 4
Notice rank 3 is skipped.
๐น 3๏ธโฃ DENSE_RANK()
Similar to RANK but does not skip numbers.
name | salary | rank
Rahul | 90000 | 1
Priya | 85000 | 2
Amit | 85000 | 2
Neha | 80000 | 3
๐น 4๏ธโฃ PARTITION BY
Used to divide rows into groups before calculation.
Example: Rank employees within each department
๐น 5๏ธโฃ LAG()
Used to access previous row values.
Example: Compare sales with previous day.
Used to access next row values.
Top 3 highest salaries
โ Difference between ROW_NUMBER, RANK, DENSE_RANK
โ Find Nth highest salary
โ Running totals using window functions
โ Compare current row with previous row
โ Rank employees by department
๐ Mini Practice Tasks
Task 1: Assign row numbers to employees by salary.
Task 2: Rank employees by salary.
Task 3: Find top 3 highest salaries using window functions.
Task 4: Calculate running total of sales.
๐ผ What You Must Master
โ ROW_NUMBER()
โ RANK()
โ DENSE_RANK()
โ PARTITION BY
โ LAG() / LEAD()
โ Running totals
These functions are used heavily in real analytics queries and SQL interviews.
Double Tap โฅ๏ธ For More
Window functions are one of the most powerful SQL features used in data analytics, reporting, and advanced SQL interviews.
๐ They allow you to perform calculations across rows without collapsing them like GROUP BY.
In simple words:
GROUP BY โ reduces rows
Window Functions โ keep rows but add calculated values
๐ง Basic Syntax of Window Functions
SELECT column, window_function()Components:
OVER (
PARTITION BY column
ORDER BY column
)
FROM table;
- OVER() โ defines the window
- PARTITION BY โ splits data into groups
- ORDER BY โ defines calculation order
๐น 1๏ธโฃ ROW_NUMBER()
Assigns a unique sequential number to rows.
SELECT name, salary, ROW_NUMBER() OVER(ORDER BY salary DESC) AS rankResult:
FROM employees;
name | salary | rank
Rahul | 90000 | 1
Priya | 85000 | 2
Amit | 85000 | 3
๐ Even if salaries are same, numbers stay unique.
๐น 2๏ธโฃ RANK()
Assigns rank but skips numbers when ties occur.
SELECT name, salary, RANK() OVER(ORDER BY salary DESC) AS rankResult:
FROM employees;
name | salary | rank
Rahul | 90000 | 1
Priya | 85000 | 2
Amit | 85000 | 2
Neha | 80000 | 4
Notice rank 3 is skipped.
๐น 3๏ธโฃ DENSE_RANK()
Similar to RANK but does not skip numbers.
SELECT name, salary, DENSE_RANK() OVER(ORDER BY salary DESC) AS rankResult:
FROM employees;
name | salary | rank
Rahul | 90000 | 1
Priya | 85000 | 2
Amit | 85000 | 2
Neha | 80000 | 3
๐น 4๏ธโฃ PARTITION BY
Used to divide rows into groups before calculation.
Example: Rank employees within each department
SELECT name, department, salary,๐ Each department gets its own ranking.
RANK() OVER(
PARTITION BY department
ORDER BY salary DESC
) AS dept_rank
FROM employees;
๐น 5๏ธโฃ LAG()
Used to access previous row values.
Example: Compare sales with previous day.
SELECT date, sales, LAG(sales) OVER(ORDER BY date) AS previous_sales๐น 6๏ธโฃ LEAD()
FROM sales;
Used to access next row values.
SELECT date, sales, LEAD(sales) OVER(ORDER BY date) AS next_salesโญ Real Data Analyst Examples
FROM sales;
Top 3 highest salaries
SELECT **Running total of sales
FROM (
SELECT name, salary, ROW_NUMBER() OVER(ORDER BY salary DESC) AS rn
FROM employees
) t
WHERE rn <= 3;
SELECT date, sales, SUM(sales) OVER(ORDER BY date) AS running_totalRank products by category
FROM sales;
SELECT product_name, category, price,๐ฏ Common Interview Questions
RANK() OVER(PARTITION BY category ORDER BY price DESC) AS rank
FROM products;
โ Difference between ROW_NUMBER, RANK, DENSE_RANK
โ Find Nth highest salary
โ Running totals using window functions
โ Compare current row with previous row
โ Rank employees by department
๐ Mini Practice Tasks
Task 1: Assign row numbers to employees by salary.
Task 2: Rank employees by salary.
Task 3: Find top 3 highest salaries using window functions.
Task 4: Calculate running total of sales.
๐ผ What You Must Master
โ ROW_NUMBER()
โ RANK()
โ DENSE_RANK()
โ PARTITION BY
โ LAG() / LEAD()
โ Running totals
These functions are used heavily in real analytics queries and SQL interviews.
Double Tap โฅ๏ธ For More
โค9
โ
Useful Platform to Practice SQL Programming ๐ง ๐ฅ๏ธ
Learning SQL is just the first step โ practice is what builds real skill. Here are the best platforms for hands-on SQL:
1๏ธโฃ LeetCode โ For Interview-Oriented SQL Practice
โข Focus: Real interview-style problems
โข Levels: Easy to Hard
โข Schema + Sample Data Provided
โข Great for: Data Analyst, Data Engineer, FAANG roles
โ Tip: Start with Easy โ filter by โDatabaseโ tag
โ Popular Section: Database โ Top 50 SQL Questions
Example Problem: โFind duplicate emails in a user tableโ โ Practice filtering, GROUP BY, HAVING
2๏ธโฃ HackerRank โ Structured & Beginner-Friendly
โข Focus: Step-by-step SQL track
โข Has certification tests (SQL Basic, Intermediate)
โข Problem sets by topic: SELECT, JOINs, Aggregations, etc.
โ Tip: Follow the full SQL track
โ Bonus: Company-specific challenges
Try: โRevising Aggregations โ The Count Functionโ โ Build confidence with small wins
3๏ธโฃ Mode Analytics โ Real-World SQL in Business Context
โข Focus: Business intelligence + SQL
โข Uses real-world datasets (e.g., e-commerce, finance)
โข Has an in-browser SQL editor with live data
โ Best for: Practicing dashboard-level queries
โ Tip: Try the SQL case studies & tutorials
4๏ธโฃ StrataScratch โ Interview Questions from Real Companies
โข 500+ problems from companies like Uber, Netflix, Google
โข Split by company, difficulty, and topic
โ Best for: Intermediate to advanced level
โ Tip: Try โHardโ questions after doing 30โ50 easy/medium
5๏ธโฃ DataLemur โ Short, Practical SQL Problems
โข Crisp and to the point
โข Good UI, fast learning
โข Real interview-style logic
โ Use when: You want fast, smart SQL drills
๐ How to Practice Effectively:
โข Spend 20โ30 mins/day
โข Focus on JOINs, GROUP BY, HAVING, Subqueries
โข Analyze problem โ write โ debug โ re-write
โข After solving, explain your logic out loud
๐งช Practice Task:
Try solving 5 SQL questions from LeetCode or HackerRank this week. Start with SELECT, WHERE, and GROUP BY.
๐ฌ Tap โค๏ธ for more!
Learning SQL is just the first step โ practice is what builds real skill. Here are the best platforms for hands-on SQL:
1๏ธโฃ LeetCode โ For Interview-Oriented SQL Practice
โข Focus: Real interview-style problems
โข Levels: Easy to Hard
โข Schema + Sample Data Provided
โข Great for: Data Analyst, Data Engineer, FAANG roles
โ Tip: Start with Easy โ filter by โDatabaseโ tag
โ Popular Section: Database โ Top 50 SQL Questions
Example Problem: โFind duplicate emails in a user tableโ โ Practice filtering, GROUP BY, HAVING
2๏ธโฃ HackerRank โ Structured & Beginner-Friendly
โข Focus: Step-by-step SQL track
โข Has certification tests (SQL Basic, Intermediate)
โข Problem sets by topic: SELECT, JOINs, Aggregations, etc.
โ Tip: Follow the full SQL track
โ Bonus: Company-specific challenges
Try: โRevising Aggregations โ The Count Functionโ โ Build confidence with small wins
3๏ธโฃ Mode Analytics โ Real-World SQL in Business Context
โข Focus: Business intelligence + SQL
โข Uses real-world datasets (e.g., e-commerce, finance)
โข Has an in-browser SQL editor with live data
โ Best for: Practicing dashboard-level queries
โ Tip: Try the SQL case studies & tutorials
4๏ธโฃ StrataScratch โ Interview Questions from Real Companies
โข 500+ problems from companies like Uber, Netflix, Google
โข Split by company, difficulty, and topic
โ Best for: Intermediate to advanced level
โ Tip: Try โHardโ questions after doing 30โ50 easy/medium
5๏ธโฃ DataLemur โ Short, Practical SQL Problems
โข Crisp and to the point
โข Good UI, fast learning
โข Real interview-style logic
โ Use when: You want fast, smart SQL drills
๐ How to Practice Effectively:
โข Spend 20โ30 mins/day
โข Focus on JOINs, GROUP BY, HAVING, Subqueries
โข Analyze problem โ write โ debug โ re-write
โข After solving, explain your logic out loud
๐งช Practice Task:
Try solving 5 SQL questions from LeetCode or HackerRank this week. Start with SELECT, WHERE, and GROUP BY.
๐ฌ Tap โค๏ธ for more!
โค14
โ๏ธ SQL Developer Roadmap
๐ SQL Basics (CREATE, DROP, USE Database)
โ๐ Data Types & DDL (Tables, Constraints - PK/FK)
โ๐ DML (INSERT, UPDATE, DELETE)
โ๐ SELECT Queries (DISTINCT, LIMIT/TOP)
โ๐ WHERE Clause (Operators, LIKE, IN, BETWEEN)
โ๐ ORDER BY & Sorting (ASC/DESC)
โ๐ Aggregate Functions (COUNT, SUM, AVG, MIN/MAX)
โ๐ GROUP BY & HAVING
โ๐ JOINs (INNER, LEFT, RIGHT, FULL)
โ๐ Subqueries
โ๐ String Functions (CONCAT, SUBSTRING, UPPER/LOWER)
โ๐ Date Functions (NOW, DATEADD, DATEDIFF)
โ๐ Window Functions (ROW_NUMBER, RANK, PARTITION BY)
โ๐ CTEs (Common Table Expressions)
โ๐ Indexes & Performance
โ๐ Transactions (BEGIN, COMMIT, ROLLBACK)
โ๐ Views & Stored Procedures
โ๐ Practice (LeetCode SQL, HackerRank)
โโ Apply for Data Analyst / Backend Roles
๐ฌ Tap โค๏ธ for more!
๐ SQL Basics (CREATE, DROP, USE Database)
โ๐ Data Types & DDL (Tables, Constraints - PK/FK)
โ๐ DML (INSERT, UPDATE, DELETE)
โ๐ SELECT Queries (DISTINCT, LIMIT/TOP)
โ๐ WHERE Clause (Operators, LIKE, IN, BETWEEN)
โ๐ ORDER BY & Sorting (ASC/DESC)
โ๐ Aggregate Functions (COUNT, SUM, AVG, MIN/MAX)
โ๐ GROUP BY & HAVING
โ๐ JOINs (INNER, LEFT, RIGHT, FULL)
โ๐ Subqueries
โ๐ String Functions (CONCAT, SUBSTRING, UPPER/LOWER)
โ๐ Date Functions (NOW, DATEADD, DATEDIFF)
โ๐ Window Functions (ROW_NUMBER, RANK, PARTITION BY)
โ๐ CTEs (Common Table Expressions)
โ๐ Indexes & Performance
โ๐ Transactions (BEGIN, COMMIT, ROLLBACK)
โ๐ Views & Stored Procedures
โ๐ Practice (LeetCode SQL, HackerRank)
โโ Apply for Data Analyst / Backend Roles
๐ฌ Tap โค๏ธ for more!
โค12
๐๐ฅ๐๐ ๐ข๐ป๐น๐ถ๐ป๐ฒ ๐ ๐ฎ๐๐๐ฒ๐ฟ๐ฐ๐น๐ฎ๐๐ ๐ข๐ป ๐๐ ๐๐ป๐ฑ๐๐๐๐ฟ๐ ๐๐
๐ฝ๐ฒ๐ฟ๐๐ ๐
Choose the Right Career Path in 2026
Learn โ Level Up โ Get Hired
๐ฏ Join this FREE Career Guidance Session & find:
โ The right tech career for YOU
โ Skills companies are hiring for
โ Step-by-step roadmap to get a job
๐ ๐ฆ๐ฎ๐๐ฒ ๐๐ผ๐๐ฟ ๐๐ฝ๐ผ๐ ๐ป๐ผ๐ (๐๐ถ๐บ๐ถ๐๐ฒ๐ฑ ๐๐ฒ๐ฎ๐๐)
https://pdlink.in/4sNAyhW
Date & Time :- 18th March 2026 , 7:00 PM
Choose the Right Career Path in 2026
Learn โ Level Up โ Get Hired
๐ฏ Join this FREE Career Guidance Session & find:
โ The right tech career for YOU
โ Skills companies are hiring for
โ Step-by-step roadmap to get a job
๐ ๐ฆ๐ฎ๐๐ฒ ๐๐ผ๐๐ฟ ๐๐ฝ๐ผ๐ ๐ป๐ผ๐ (๐๐ถ๐บ๐ถ๐๐ฒ๐ฑ ๐๐ฒ๐ฎ๐๐)
https://pdlink.in/4sNAyhW
Date & Time :- 18th March 2026 , 7:00 PM
โค1
๐ฅ Top SQL Interview Questions with Answers
๐ฏ 1๏ธโฃ Find 2nd Highest Salary
๐ Table: employees
id | name | salary
1 | Rahul | 50000
2 | Priya | 70000
3 | Amit | 60000
4 | Neha | 70000
โ Problem Statement: Find the second highest distinct salary from the employees table.
โ Solution
SELECT MAX(salary) FROM employees WHERE salary < ( SELECT MAX(salary) FROM employees );
๐ฏ 2๏ธโฃ Find Nth Highest Salary
๐ Table: employees
id | name | salary
1 | A | 100
2 | B | 200
3 | C | 300
4 | D | 200
โ Problem Statement: Write a query to find the 3rd highest salary.
โ Solution
SELECT salary FROM ( SELECT salary, DENSE_RANK() OVER(ORDER BY salary DESC) r FROM employees ) t WHERE r = 3;
๐ฏ 3๏ธโฃ Find Duplicate Records
๐ Table: employees
id | name
1 | Rahul
2 | Amit
3 | Rahul
4 | Neha
โ Problem Statement: Find all duplicate names in the employees table.
โ Solution
SELECT name, COUNT(*) FROM employees GROUP BY name HAVING COUNT(*) > 1;
๐ฏ 4๏ธโฃ Customers with No Orders
๐ Table: customers
customer_id | name
1 | Rahul
2 | Priya
3 | Amit
๐ Table: orders
order_id | customer_id
101 | 1
102 | 2
โ Problem Statement: Find customers who have not placed any orders.
โ Solution
SELECT c.name FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id WHERE o.customer_id IS NULL;
๐ฏ 5๏ธโฃ Top 3 Salaries per Department
๐ Table: employees
name | department | salary
A | IT | 100
B | IT | 200
C | IT | 150
D | HR | 120
E | HR | 180
โ Problem Statement: Find the top 3 highest salaries in each department.
โ Solution
SELECT * FROM ( SELECT name, department, salary, ROW_NUMBER() OVER( PARTITION BY department ORDER BY salary DESC ) r FROM employees ) t WHERE r <= 3;
๐ฏ 6๏ธโฃ Running Total of Sales
๐ Table: sales
date | sales
2024-01-01 | 100
2024-01-02 | 200
2024-01-03 | 300
โ Problem Statement: Calculate the running total of sales by date.
โ Solution
SELECT date, sales, SUM(sales) OVER(ORDER BY date) AS running_total FROM sales;
๐ฏ 7๏ธโฃ Employees Above Average Salary
๐ Table: employees
name | salary
A | 100
B | 200
C | 300
โ Problem Statement: Find employees earning more than the average salary.
โ Solution
SELECT name, salary FROM employees WHERE salary > ( SELECT AVG(salary) FROM employees );
๐ฏ 8๏ธโฃ Department with Highest Total Salary
๐ Table: employees
name | department | salary
A | IT | 100
B | IT | 200
C | HR | 500
โ Problem Statement: Find the department with the highest total salary.
โ Solution
SELECT department, SUM(salary) AS total_salary FROM employees GROUP BY department ORDER BY total_salary DESC LIMIT 1;
๐ฏ 9๏ธโฃ Customers Who Placed Orders
๐ Tables: Same as Q4
โ Problem Statement: Find customers who have placed at least one order.
โ Solution
SELECT name FROM customers c WHERE EXISTS ( SELECT 1 FROM orders o WHERE c.customer_id = o.customer_id );
๐ฏ ๐ Remove Duplicate Records
๐ Table: employees
id | name
1 | Rahul
2 | Rahul
3 | Amit
โ Problem Statement: Delete duplicate records but keep one unique record.
โ Solution
DELETE FROM employees WHERE id NOT IN ( SELECT MIN(id) FROM employees GROUP BY name );
๐ Pro Tip:
๐ In interviews:
First explain logic
Then write query
Then optimize
Double Tap โฅ๏ธ For More
๐ฏ 1๏ธโฃ Find 2nd Highest Salary
๐ Table: employees
id | name | salary
1 | Rahul | 50000
2 | Priya | 70000
3 | Amit | 60000
4 | Neha | 70000
โ Problem Statement: Find the second highest distinct salary from the employees table.
โ Solution
SELECT MAX(salary) FROM employees WHERE salary < ( SELECT MAX(salary) FROM employees );
๐ฏ 2๏ธโฃ Find Nth Highest Salary
๐ Table: employees
id | name | salary
1 | A | 100
2 | B | 200
3 | C | 300
4 | D | 200
โ Problem Statement: Write a query to find the 3rd highest salary.
โ Solution
SELECT salary FROM ( SELECT salary, DENSE_RANK() OVER(ORDER BY salary DESC) r FROM employees ) t WHERE r = 3;
๐ฏ 3๏ธโฃ Find Duplicate Records
๐ Table: employees
id | name
1 | Rahul
2 | Amit
3 | Rahul
4 | Neha
โ Problem Statement: Find all duplicate names in the employees table.
โ Solution
SELECT name, COUNT(*) FROM employees GROUP BY name HAVING COUNT(*) > 1;
๐ฏ 4๏ธโฃ Customers with No Orders
๐ Table: customers
customer_id | name
1 | Rahul
2 | Priya
3 | Amit
๐ Table: orders
order_id | customer_id
101 | 1
102 | 2
โ Problem Statement: Find customers who have not placed any orders.
โ Solution
SELECT c.name FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id WHERE o.customer_id IS NULL;
๐ฏ 5๏ธโฃ Top 3 Salaries per Department
๐ Table: employees
name | department | salary
A | IT | 100
B | IT | 200
C | IT | 150
D | HR | 120
E | HR | 180
โ Problem Statement: Find the top 3 highest salaries in each department.
โ Solution
SELECT * FROM ( SELECT name, department, salary, ROW_NUMBER() OVER( PARTITION BY department ORDER BY salary DESC ) r FROM employees ) t WHERE r <= 3;
๐ฏ 6๏ธโฃ Running Total of Sales
๐ Table: sales
date | sales
2024-01-01 | 100
2024-01-02 | 200
2024-01-03 | 300
โ Problem Statement: Calculate the running total of sales by date.
โ Solution
SELECT date, sales, SUM(sales) OVER(ORDER BY date) AS running_total FROM sales;
๐ฏ 7๏ธโฃ Employees Above Average Salary
๐ Table: employees
name | salary
A | 100
B | 200
C | 300
โ Problem Statement: Find employees earning more than the average salary.
โ Solution
SELECT name, salary FROM employees WHERE salary > ( SELECT AVG(salary) FROM employees );
๐ฏ 8๏ธโฃ Department with Highest Total Salary
๐ Table: employees
name | department | salary
A | IT | 100
B | IT | 200
C | HR | 500
โ Problem Statement: Find the department with the highest total salary.
โ Solution
SELECT department, SUM(salary) AS total_salary FROM employees GROUP BY department ORDER BY total_salary DESC LIMIT 1;
๐ฏ 9๏ธโฃ Customers Who Placed Orders
๐ Tables: Same as Q4
โ Problem Statement: Find customers who have placed at least one order.
โ Solution
SELECT name FROM customers c WHERE EXISTS ( SELECT 1 FROM orders o WHERE c.customer_id = o.customer_id );
๐ฏ ๐ Remove Duplicate Records
๐ Table: employees
id | name
1 | Rahul
2 | Rahul
3 | Amit
โ Problem Statement: Delete duplicate records but keep one unique record.
โ Solution
DELETE FROM employees WHERE id NOT IN ( SELECT MIN(id) FROM employees GROUP BY name );
๐ Pro Tip:
๐ In interviews:
First explain logic
Then write query
Then optimize
Double Tap โฅ๏ธ For More
โค11
๐๐ฟ๐ฒ๐๐ต๐ฒ๐ฟ๐ ๐๐ฎ๐ป ๐๐ฒ๐ ๐ฎ ๐ฏ๐ฌ ๐๐ฃ๐ ๐๐ผ๐ฏ ๐ข๐ณ๐ณ๐ฒ๐ฟ ๐๐ถ๐๐ต ๐๐ & ๐๐ฆ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป๐
IIT Roorkee offering AI & Data Science Certification Program
๐ซLearn from IIT ROORKEE Professors
โ Students & Fresher can apply
๐ IIT Certification Program
๐ผ 5000+ Companies Placement Support
Deadline: 22nd March 2026
๐ ๐ฅ๐ฒ๐ด๐ถ๐๐๐ฒ๐ฟ ๐ก๐ผ๐ ๐ :-
https://pdlink.in/4kucM7E
Big Opportunity, Do join asap!
IIT Roorkee offering AI & Data Science Certification Program
๐ซLearn from IIT ROORKEE Professors
โ Students & Fresher can apply
๐ IIT Certification Program
๐ผ 5000+ Companies Placement Support
Deadline: 22nd March 2026
๐ ๐ฅ๐ฒ๐ด๐ถ๐๐๐ฒ๐ฟ ๐ก๐ผ๐ ๐ :-
https://pdlink.in/4kucM7E
Big Opportunity, Do join asap!
๐ Complete SQL Syllabus Roadmap (Beginner to Expert) ๐๏ธ
๐ฐ Beginner Level:
1. Intro to Databases: What are databases, Relational vs. Non-Relational
2. SQL Basics: SELECT, FROM, WHERE
3. Data Types: INT, VARCHAR, DATE, BOOLEAN, etc.
4. Operators: Comparison, Logical (AND, OR, NOT)
5. Sorting & Filtering: ORDER BY, LIMIT, DISTINCT
6. Aggregate Functions: COUNT, SUM, AVG, MIN, MAX
7. GROUP BY and HAVING: Grouping Data and Filtering Groups
8. Basic Projects: Creating and querying a simple database (e.g., a student database)
โ๏ธ Intermediate Level:
1. Joins: INNER, LEFT, RIGHT, FULL OUTER JOIN
2. Subqueries: Using queries within queries
3. Indexes: Improving Query Performance
4. Data Modification: INSERT, UPDATE, DELETE
5. Transactions: ACID Properties, COMMIT, ROLLBACK
6. Constraints: PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK, DEFAULT
7. Views: Creating Virtual Tables
8. Stored Procedures & Functions: Reusable SQL Code
9. Date and Time Functions: Working with Date and Time Data
10. Intermediate Projects: Designing and querying a more complex database (e.g., an e-commerce database)
๐ Expert Level:
1. Window Functions: RANK, ROW_NUMBER, LAG, LEAD
2. Common Table Expressions (CTEs): Recursive and Non-Recursive
3. Performance Tuning: Query Optimization Techniques
4. Database Design & Normalization: Understanding Database Schemas (Star, Snowflake)
5. Advanced Indexing: Clustered, Non-Clustered, Filtered Indexes
6. Database Administration: Backup and Recovery, Security, User Management
7. Working with Large Datasets: Partitioning, Data Warehousing Concepts
8. NoSQL Databases: Introduction to MongoDB, Cassandra, etc. (optional)
9. SQL Injection Prevention: Secure Coding Practices
10. Expert Projects: Designing, optimizing, and managing a large-scale database (e.g., a social media database)
๐ก Bonus: Learn about Database Security, Cloud Databases (AWS RDS, Azure SQL Database, Google Cloud SQL), and Data Modeling Tools.
๐ Tap โค๏ธ for more
๐ฐ Beginner Level:
1. Intro to Databases: What are databases, Relational vs. Non-Relational
2. SQL Basics: SELECT, FROM, WHERE
3. Data Types: INT, VARCHAR, DATE, BOOLEAN, etc.
4. Operators: Comparison, Logical (AND, OR, NOT)
5. Sorting & Filtering: ORDER BY, LIMIT, DISTINCT
6. Aggregate Functions: COUNT, SUM, AVG, MIN, MAX
7. GROUP BY and HAVING: Grouping Data and Filtering Groups
8. Basic Projects: Creating and querying a simple database (e.g., a student database)
โ๏ธ Intermediate Level:
1. Joins: INNER, LEFT, RIGHT, FULL OUTER JOIN
2. Subqueries: Using queries within queries
3. Indexes: Improving Query Performance
4. Data Modification: INSERT, UPDATE, DELETE
5. Transactions: ACID Properties, COMMIT, ROLLBACK
6. Constraints: PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK, DEFAULT
7. Views: Creating Virtual Tables
8. Stored Procedures & Functions: Reusable SQL Code
9. Date and Time Functions: Working with Date and Time Data
10. Intermediate Projects: Designing and querying a more complex database (e.g., an e-commerce database)
๐ Expert Level:
1. Window Functions: RANK, ROW_NUMBER, LAG, LEAD
2. Common Table Expressions (CTEs): Recursive and Non-Recursive
3. Performance Tuning: Query Optimization Techniques
4. Database Design & Normalization: Understanding Database Schemas (Star, Snowflake)
5. Advanced Indexing: Clustered, Non-Clustered, Filtered Indexes
6. Database Administration: Backup and Recovery, Security, User Management
7. Working with Large Datasets: Partitioning, Data Warehousing Concepts
8. NoSQL Databases: Introduction to MongoDB, Cassandra, etc. (optional)
9. SQL Injection Prevention: Secure Coding Practices
10. Expert Projects: Designing, optimizing, and managing a large-scale database (e.g., a social media database)
๐ก Bonus: Learn about Database Security, Cloud Databases (AWS RDS, Azure SQL Database, Google Cloud SQL), and Data Modeling Tools.
๐ Tap โค๏ธ for more
โค5๐1
SQL Cheat Sheet for Data Analysts ๐๏ธ๐
1. SELECT
What it is: Used to choose columns from a table
What it does: Returns specific columns of data
Query: Fetch name and salary
2. FROM
What it is: Specifies the table
What it does: Tells SQL where to get data from
Query: Fetch all data from employees
3. WHERE
What it is: Filters rows based on condition
What it does: Returns only matching rows
Query: Employees with salary > 30000
4. ORDER BY
What it is: Sorts the data
What it does: Arranges rows in order
Query: Sort by salary (highest first)
5. COUNT()
What it is: Counts rows
What it does: Returns total records
Query: Count employees
6. AVG()
What it is: Calculates average
What it does: Returns mean value
Query: Average salary
7. GROUP BY
What it is: Groups rows by column
What it does: Applies aggregation per group
Query: Avg salary per department
8. HAVING
What it is: Filters grouped data
What it does: Returns filtered groups
Query: Departments with avg salary > 40000
9. INNER JOIN
What it is: Combines matching rows from tables
What it does: Returns common data
Query: Employees with department names
10. LEFT JOIN
What it is: Combines all left + matching right
What it does: Returns all left table data
Query: All employees with departments
11. CASE WHEN
What it is: Conditional logic
What it does: Creates values based on condition
Query: Categorize salary
12. SUBQUERY
What it is: Query inside another query
What it does: Uses result of inner query
Query: Salary above average
13. RANK()
What it is: Window function
What it does: Assigns rank without grouping
Query: Rank employees by salary
14. DISTINCT
What it is: Removes duplicates
What it does: Returns unique values
Query: Unique departments
15. LIKE
What it is: Pattern matching
What it does: Filters text patterns
Query: Names starting with A
Double Tap โฅ๏ธ For More
1. SELECT
What it is: Used to choose columns from a table
What it does: Returns specific columns of data
Query: Fetch name and salary
SELECT name, salary
FROM employees;
2. FROM
What it is: Specifies the table
What it does: Tells SQL where to get data from
Query: Fetch all data from employees
SELECT *
FROM employees;
3. WHERE
What it is: Filters rows based on condition
What it does: Returns only matching rows
Query: Employees with salary > 30000
SELECT *
FROM employees
WHERE salary > 30000;
4. ORDER BY
What it is: Sorts the data
What it does: Arranges rows in order
Query: Sort by salary (highest first)
SELECT *
FROM employees
ORDER BY salary DESC;
5. COUNT()
What it is: Counts rows
What it does: Returns total records
Query: Count employees
SELECT COUNT(*)
FROM employees;
6. AVG()
What it is: Calculates average
What it does: Returns mean value
Query: Average salary
SELECT AVG(salary)
FROM employees;
7. GROUP BY
What it is: Groups rows by column
What it does: Applies aggregation per group
Query: Avg salary per department
SELECT department, AVG(salary)
FROM employees
GROUP BY department;
8. HAVING
What it is: Filters grouped data
What it does: Returns filtered groups
Query: Departments with avg salary > 40000
SELECT department, AVG(salary)
FROM employees
GROUP BY department
HAVING AVG(salary) > 40000;
9. INNER JOIN
What it is: Combines matching rows from tables
What it does: Returns common data
Query: Employees with department names
SELECT e.name, d.department_name
FROM employees e
INNER JOIN departments d
ON e.dept_id = d.dept_id;
10. LEFT JOIN
What it is: Combines all left + matching right
What it does: Returns all left table data
Query: All employees with departments
SELECT e.name, d.department_name
FROM employees e
LEFT JOIN departments d
ON e.dept_id = d.dept_id;
11. CASE WHEN
What it is: Conditional logic
What it does: Creates values based on condition
Query: Categorize salary
SELECT name,
CASE
WHEN salary > 40000 THEN 'High'
ELSE 'Low'
END AS category
FROM employees;
12. SUBQUERY
What it is: Query inside another query
What it does: Uses result of inner query
Query: Salary above average
SELECT name, salary
FROM employees
WHERE salary > (
SELECT AVG(salary)
FROM employees
);
13. RANK()
What it is: Window function
What it does: Assigns rank without grouping
Query: Rank employees by salary
SELECT name, salary,
RANK() OVER (ORDER BY salary DESC) AS rank
FROM employees;
14. DISTINCT
What it is: Removes duplicates
What it does: Returns unique values
Query: Unique departments
SELECT DISTINCT department
FROM employees;
15. LIKE
What it is: Pattern matching
What it does: Filters text patterns
Query: Names starting with A
SELECT *
FROM employees
WHERE name LIKE 'A%';
Double Tap โฅ๏ธ For More
โค15๐1