Data Analytics
110K subscribers
147 photos
2 files
856 links
Perfect channel to learn Data Analytics

Learn SQL, Python, Alteryx, Tableau, Power BI and many more

For Promotions: @coderfun @love_data
Download Telegram
βœ¨πŸ“ˆHOW TO FUTURE-PROOF YOUR IT CAREER IN THE AI ERAπŸ•Ί

πŸ—“ Date: 11 April 2026
⏰ 7 – 9 PM (IST)
πŸ’» FREE Online Masterclass

🌟Perks of Attending:
βœ… Exclusive 90-Day Placement Plan
βœ… Tech & Non-Tech Career Paths Explained
βœ… Insider Interview Preparation Tips
βœ… Certificate of Participation
βœ… Skill-Building Ebooks
βœ… Surprise Bonus Gift

⚑ Limited Slots Available!
πŸ‘‰ Register Now for FREE & secure your seat!
https://link.guvi.in/programming_experts03100
❀12
π—œπ—»π˜π—²π—Ώπ˜ƒπ—Άπ—²π˜„π—²π—Ώ: You have 2 minutes to solve this SQL query.

Find the second highest salary in each department from the employees table, excluding any department with fewer than 2 employees.

𝗠𝗲: Challenge accepted!

SELECT 
department,
MAX(salary) AS second_highest_salary
FROM (
SELECT
department,
salary,
ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) as rn
FROM employees
) ranked
WHERE rn = 2
GROUP BY department;


I used a subquery with ROW_NUMBER() window function partitioned by department to rank salaries in descending order within each department. The outer query then filters for rank 2 (second highest) and groups to get distinct departments. This demonstrates mastery of window functions, which are essential for advanced analytics and ranking problems.

𝗧𝗢𝗽 𝗳𝗼𝗿 π—¦π—€π—Ÿ 𝗝𝗼𝗯 π—¦π—²π—²π—Έπ—²π—Ώπ˜€:
Window functions like ROW_NUMBER(), RANK(), and DENSE_RANK() unlock complex ranking and analyticsβ€”practice them daily to ace behavioral and technical rounds!

React with ❀️ for more
❀23πŸ‘1πŸ‘1
βœ… Power BI Interview Questions with Answers

1. What is DAX? 
DAX (Data Analysis Expressions) is a formula language in Power BI used to create calculated columns, measures, and tables (e.g., SUM(), CALCULATE(), FILTER()) for business logic and KPIs.

2. What is the difference between Power Query and Power Pivot? 
β€’ Power Query: used for data loading, cleaning, and transforming (ETL) before loading into the model.
β€’ Power Pivot: in‑memory data model and engine for DAX calculations and relationships (used during/after load).

3. What is the difference between measure vs calculated column? 
β€’ Measure: calculated at query time, used in visuals (e.g., summaries, ratios).
β€’ Calculated column: computed at refresh time, stored in the model (uses more memory). Prefer measures for aggregations.

4. Explain CALCULATE() function. 
CALCULATE() changes the context of a calculation by applying filters. 
Example: Total Sales = CALCULATE(SUM(Sales[Amount]), Sales[Region] = "West") computes sum only for West region.

5. What are relationships (1:M, M:M)? 
β€’ 1:M (one‑to‑many): one row in the β€œ1” table links to many rows in the β€œM” table (most common).
β€’ M:M (many‑to‑many): handled via an intermediate bridge table with foreign keys on both sides.

6. How do you handle many‑to‑many? 
Create a bridge table (junction table) that contains foreign keys to both related tables. Then set 1:M relationships from each original table to the bridge.

7. What is row‑level security (RLS)? 
RLS restricts which rows a user can see in a report (e.g., by SalesRegion = β€œUserRegion”). Defined in the model with DAX filter expressions and applied by user roles.

8. How do you setup incremental refresh? 
β€’ Mark your tables as β€œincrementally refreshable” in the model.
β€’ Define a date/time column and ranges (e.g., last 3 years full, last 60 days incremental).
β€’ Set refresh schedule in the Power BI service with gateways if needed.

9. What is the difference between filters vs slicers? 
β€’ Filters: rules applied behind the scenes (e.g., in page/report level filters) that always apply.
β€’ Slicers: interactive controls on the report canvas that users click to change what data is shown.

10. What is a data model? 
A data model is the structure in Power BI that holds tables, relationships, calculated columns, measures, and hierarchies, forming the semantic layer for reporting.

11. How do you publish and share reports? 
β€’ Publish from Power BI Desktop to a workspace in Power BI Service.
β€’ Share via apps, workspaces, or by granting access to specific users/groups; use RLS and sharing permissions to control who sees what.

12. What is Performance Analyzer tool? 
Performance Analyzer in Power BI Desktop records how long each visual takes to render and which DAX queries run, helping identify slow visuals or large queries.

13. How do you create month‑on‑month growth DAX? 
MoM Growth =
VAR CurrentSales = [Total Sales] 
VAR PreviousSales = CALCULATE([Total Sales], DATEADD('Date'[Date], -1, MONTH)) 
RETURN 
DIVIDE(CurrentSales - PreviousSales, PreviousSales)

14. How do you use custom visuals? 
Download a custom visual from the marketplace, add it to the report in Power BI Desktop or Service, then configure like a native visual (fields, formatting, interactivity).

15. What is gateway for refresh? 
An on‑premises gateway connects Power BI Service to data sources behind your firewall (e.g., SQL Server, file shares). It enables scheduled refresh for datasets that pull from those sources.

16. What is a .pbix file? 
A .pbix file is the Power BI Desktop project file that contains the report layout, queries, data model, and DAX logic. It can be opened in Power BI Desktop or published to the service.

17. What are quick measures examples? 
Quick measures are auto‑generated DAX calculations with a UI. Examples: 
β€’ Average of a column.
❀17
18. What is data blending in Power BI? 
Data blending (sometimes confused with β€œmerge”) usually refers to combining fields from multiple tables at the visualization level, often via relationships or calculated columns/measures rather than ETL-level joins.

19. How do you optimize large datasets? 
β€’ Use a star-schema model, avoid unnested structures.
β€’ Use appropriate data types, remove unnecessary columns.
β€’ Prefer measures over large calculated columns, enable incremental refresh, and push heavy filters to the source when possible.

20. What is Get Data? 
β€œGet Data” (in Power BI Desktop) is the Power Query interface that lets you connect to various sources (SQL, Excel, Web, etc.), load, and transform data into the model.

Double Tap ❀️ For More
❀11
πŸ’Ό Data Analyst Interview Questions β€” Part 1 (HR Round) 

🧠 1) Tell me about yourself. 
πŸ‘‰ Answer: 
"I'm a Data Analyst proficient in SQL, Python, Power BI, and Excel. I've built dashboards and delivered business insights from complex datasets. Passionate about turning data into decisions and excited to contribute here!"

🎯 2) Why should we hire you for this Data Analyst role? 
πŸ‘‰ Answer: 
"I deliver actionable insights using SQL, Python, and visualization toolsβ€”not just theory. I'm quick to learn new tools and focused on solving real business problems with data."

πŸ“‰ 3) What are your weaknesses as a data analyst? 
πŸ‘‰ Answer: 
"Sometimes I focus too much on perfecting data cleaning, but I'm learning to prioritize impact and use automation to meet deadlines effectively." 

⚠️ Never say "I have no weaknesses"

πŸš€ 4) What are your key strengths? 
πŸ‘‰ Answer: 
"Strong analytical thinking, quick mastery of tools like Power BI/SQL, and ability to simplify complex data into clear business stories."

🧩 5) Describe a challenging situation you faced in a project. 
πŸ‘‰ Answer: 
"Handled messy sales data causing forecast errors. Used Python (pandas) + SQL for cleaning, built Power BI dashboardβ€”improved accuracy 30% and strengthened my ETL skills."

🀝 6) How do you work in a team environment? 
πŸ‘‰ Answer: 
"I communicate insights clearly through dashboards/reports, take ownership of analysis tasks, collaborate via Git/shared drives, and help teammates with SQL queries."

⏳ 7) How do you manage tight deadlines on analysis projects? 
πŸ‘‰ Answer: 
"I prioritize by business impact, break into steps (ETL β†’ analysis β†’ viz), and track progress with Jira/Trello for consistent delivery."

πŸ”„ 8) Are you open to learning new data tools and technologies? 
πŸ‘‰ Answer: 
"Absolutely! I continuously upskill in areas like advanced Python ML libraries, Tableau, or cloud analytics to stay impactful."

πŸ’¬ 9) Do you have any questions for us? 
πŸ‘‰ Answer: 
"Yes: 
β€’ What does a typical day look like for a Data Analyst here?
β€’ What tools does your team primarily use (Power BI, Tableau, etc.)?"

🧠 10) Where do you see yourself in 2-3 years? 
πŸ‘‰ Answer: 
"As a Senior Data Analyst leading projects, building predictive models, and driving strategic business decisions with data."

Double Tap ❀️ For More!
❀29πŸ‘1πŸ‘Ž1
π—œπ—»π˜π—²π—Ώπ˜ƒπ—Άπ—²π˜„π—²π—Ώ: You have 2 minutes to solve this SQL query.
From the employees table, retrieve the employee name, department, and their salary rank within the department (highest salary rank 1).

𝗠𝗲: Challenge accepted!

SELECT 
name,
department,
salary,
DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS salary_rank
FROM employees;

I applied DENSE_RANK() window function partitioned by department and ordered by descending salary to assign ranks within each department. Unlike ROW_NUMBER(), DENSE_RANK() handles ties by assigning the same rank without gaps. This is ideal for leaderboards or performance analytics.

𝗧𝗢𝗽 𝗳𝗼𝗿 π—¦π—€π—Ÿ 𝗝𝗼𝗯 π—¦π—²π—²π—Έπ—²π—Ώπ˜€:
Master window function differences (ROW_NUMBER vs RANK vs DENSE_RANK)β€”they're interview staples for deduping, paging, and top-N queries!

React with ❀️ for more
❀11πŸ‘7
βœ… Complete Roadmap to Learn SQL (Structured Query Language) πŸ§ πŸ’»

Week 1: SQL Basics
- What is SQL and how databases work
- Install MySQL Workbench or PostgreSQL
- Learn SELECT, FROM, WHERE
- Filtering data with conditions
- Practice basic queries
Example: Fetch all employees, filter salary > 50k

Week 2: Sorting and Aggregation
- ORDER BY (sorting data)
- Aggregate functions: COUNT, SUM, AVG, MIN, MAX
- GROUP BY concept
- HAVING clause
Example: Department-wise average salary

Week 3: Joins (Most Important πŸ”₯)
- INNER JOIN
- LEFT JOIN, RIGHT JOIN
- FULL JOIN
- Self Join
Example: Combine employees and departments tables

Week 4: Advanced Filtering
- IN, BETWEEN, LIKE
- Wildcards (% , _)
- NULL handling (IS NULL, IS NOT NULL)
- CASE statements
Example: Categorize customers based on spending

Week 5: Subqueries
- Nested queries
- Correlated subqueries
- Using subqueries in SELECT, WHERE
Example: Find employees earning above average salary

Week 6: Window Functions (High Value πŸ’°)
- OVER() clause
- ROW_NUMBER(), RANK(), DENSE_RANK()
- PARTITION BY
Example: Rank employees by salary within each department

Week 7: CTE & Views
- Common Table Expressions (WITH)
- Temporary vs permanent views
- Simplify complex queries
Example: Multi-step data transformation

Week 8: Data Modification
- INSERT, UPDATE, DELETE
- TRUNCATE vs DELETE
- Constraints (PRIMARY KEY, FOREIGN KEY)
Example: Update employee salary

Week 9: Indexing & Performance
- What are indexes
- Query optimization basics
- EXPLAIN keyword
Example: Speed up large table queries

Week 10: Working with Real Data
- Import CSV data
- Data cleaning in SQL
- Handling duplicates
- Basic transformations
Example: Clean messy sales dataset

Week 11: Mini Projects
- Write complex queries
- Solve real-world case studies
- Focus on business logic
Examples: Sales dashboard queries, Customer segmentation

Week 12: Final Preparation
- Revise all concepts
- Practice interview questions
- Solve SQL challenges on LeetCode / HackerRank
- Mock interviews

Daily Rule for You
- Practice SQL 60 minutes daily
- Solve 5 queries daily
- Revise previous queries weekly

πŸ”₯ Pro Tip
- Focus more on JOINS + WINDOW FUNCTIONS
- Practice real datasets, not just theory
- Think in terms of β€œbusiness questions”

Double Tap ❀️ For Detailed Explanation
❀57
πŸ’Ό Top 20 Frequently Asked Data Analyst Interview Questions

🧠 1) Can you walk me through the tools you use for data analysis?
πŸ‘‰ Answer: Absolutely! For data extraction I use SQL to query databases like MySQL and PostgreSQL. For cleaning and analysis, Python with pandas and NumPy is my go-to. Excel for quick pivots and Power BI/Tableau for interactive dashboards. I pick the right tool based on data size and stakeholder needs.

🎯 2) Write a SQL query to find the 2nd highest salary from employees table.
πŸ‘‰ Answer:
SELECT MAX(salary) as second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
Follow-up: Or using window functions: DENSE_RANK() OVER (ORDER BY salary DESC)

πŸ“Š 3) Explain INNER JOIN vs LEFT JOIN with a business example.
πŸ‘‰ Answer: INNER JOIN gives only matching records. LEFT JOIN gives all from left table + matches from right.
Example: Customer orders analysis - LEFT JOIN keeps customers with zero orders to see churn patterns.

πŸ” 4) How would you handle missing values in a sales dataset?
πŸ‘‰ Answer: Step 1: df.isnull().sum() to assess impact. Step 2: For numbers - impute median (df.fillna(df.median())). For categories - mode. Step 3: Flag imputed values for transparency. Never drop >5% without business justification.

🧩 5) What's pandas groupby() and write an example?
πŸ‘‰ Answer:
# Sales by region + month
df.groupby(['region', 'month'])['revenue'].agg({
'mean': 'mean',
'total': 'sum',
'records': 'count'
}).round(2)
Split -> Apply -> Combine pattern!

πŸ“ˆ 6) When would you normalize vs denormalize a database?
πŸ‘‰ Answer: Normalize for transactional systems (OLTP) to save storage. Denormalize for analytics (OLAP) for faster queries. Example: Star schema with fact/dimension tables.

πŸ”’ 7) VLOOKUP vs INDEX+MATCH - which is better and why?
πŸ‘‰ Answer: INDEX+MATCH wins! VLOOKUP breaks if columns shift and only looks right.
=INDEX(sales_range, MATCH(A2, id_range, 0))
Dynamic, safer, 2-way lookup.

πŸ“‰ 8) Difference between COUNT() vs COUNT(column_name)?
πŸ‘‰ Answer: COUNT(
): Total rows including NULLs. COUNT(column): Non-null values only. Use COUNT() for total records, COUNT(sales) to exclude null sales.

βš™οΈ 9) How do you identify and remove duplicates in pandas?
πŸ‘‰ Answer:
# Find duplicates
dupe_count = df.duplicated(subset=['email']).sum()
print(f"Found {dupe_count} duplicates")

# Remove (keep first)
df_clean = df.drop_duplicates(subset=['email'], keep='first')
Always check business logic first!

🧠 10) Name 4 SQL aggregate functions with a practical example.
πŸ‘‰ Answer:
SELECT
dept,
COUNT(
) as headcount,
AVG(salary) as avg_salary,
MAX(salary) as top_earner,
SUM(salary) as payroll
FROM employees
GROUP BY dept;
πŸ“Š 11) Sales dropped 20% last quarter. Walk me through your analysis.
πŸ‘‰ Answer: Framework:
1️⃣ Segment - Product/Category/Region/Customer
2️⃣ Trends - YoY, MoM, seasonality
3️⃣ Funnel - Where drop occurs
4️⃣ External - Competitor pricing, marketing
Dashboard: Drill-down + alerts for anomalies.

🎯 12) What's the difference between Data Analyst and Data Scientist?
πŸ‘‰ Answer: DA: SQL/Excel/Dashboards = 'What happened?' DS: ML/Python/R = 'What will happen?'
Analogy: DA = Rearview mirror, DS = Crystal ball. Most value from clean DA first!

πŸ” 13) Write a SQL window function to rank salaries by department.
πŸ‘‰ Answer:
SELECT name, dept, salary,
RANK() OVER (PARTITION BY dept ORDER BY salary DESC) as dept_rank
FROM employees;
🧩 14) How do you create a pivot table showing sales by region/month?
πŸ‘‰ Answer: Excel: Insert -> PivotTable -> Rows: Region -> Columns: Month -> Values: Sum of Sales -> Slicers for filters. Power BI: Drag-drop + matrix visual.

πŸ“ˆ 15) Explain correlation vs causation with an example.
πŸ‘‰ Answer: Classic: Ice cream sales correlate with drownings (both peak summer)

Correlation β‰  Causation. Need experiments to prove cause-effect.
❀10πŸ‘1
πŸ”’ 16) How do you merge customer and orders dataframes on customer_id?
πŸ‘‰ Answer:
# Keep all customers (even no orders)
merged = pd.merge(customers, orders, on='customer_id', how='left')
LEFT JOIN = Industry standard for customer analytics!

πŸ“‰ 17) What are 5 must-have KPIs for an e-commerce dashboard?
πŸ‘‰ Answer:
1. Revenue (vs target)
2. AOV
3. Conversion Rate
4. Cart Abandonment
5. Customer Acquisition Cost. Trend + Target + YoY always!

βš™οΈ 18) Your SQL query is running slow. How do you optimize?
πŸ‘‰ Answer:
Top 5 fixes:
1. Indexes on WHERE/JOIN columns
2. EXPLAIN query plan
3. Avoid SELECT *
4. Limit subqueries
5. Aggregate at source.

🧠 19) Tell me about a time your data analysis failed. What happened?
πŸ‘‰ Answer: Situation: Dashboard showed wrong trends. Problem: Timezone mismatch in sales data. Fix: Added CONVERT_TZ() in SQL + data validation layer. Result: 100% accuracy, saved stakeholder trust.

πŸ’¬ 20) Do you have any questions for us?
πŸ‘‰ Answer: 1. What are the top 3 metrics leadership cares about? 2. What's your biggest data challenge? 3. How do you measure success in this role after 90 days?

Double Tap ❀️ For More!
❀7πŸ‘2
πŸ”₯ Thanks for the amazing response on SQL Roadmap

Let’s start with the first topic of the SQL Roadmap:

βœ… What is SQL & How Databases Work

🧠 What is SQL?
SQL (Structured Query Language) is used to communicate with databases.

πŸ‘‰ In simple words: SQL helps you store, retrieve, update, and delete data.

Think like this πŸ‘‡
Excel β†’ You manually filter data
SQL β†’ You write a query β†’ Data comes instantly ⚑

πŸ—ƒ What is a Database?
A database is a place where data is stored in an organized way.

Example: Student records, Employee data, Orders from an e-commerce website

πŸ“Š Types of Databases

1️⃣ Relational Database (RDBMS)
- Data stored in tables (rows & columns)
- Uses SQL
- Example: MySQL, PostgreSQL

2️⃣ Non-Relational Database (NoSQL)
- Data stored as JSON, documents, key-value
- Flexible structure
- Example: MongoDB

🧩 Key Terms You Must Know
- Table β†’ Like Excel sheet
- Row β†’ One record (one entry)
- Column β†’ One field (like name, age)
- Primary Key β†’ Unique ID (no duplicates)

Example Table:

id name salary
1 Amit 50000
2 Ravi 60000

βš™οΈ How SQL Works (Simple Flow)
1️⃣ You write a query
2️⃣ Database processes it
3️⃣ Result is returned

Example: SELECT * FROM employees;

πŸ‘‰ This means: β€œGive me all data from employees table”

πŸ’‘ Real-Life Example
Imagine Swiggy/Zomato πŸ” When you search β€œPizza”:

πŸ‘‰ SQL runs in background
πŸ‘‰ Fetches restaurants with pizza
πŸ‘‰ Shows results instantly

🎯 Your Task Today
βœ” Install MySQL Workbench or PostgreSQL
βœ” Understand tables, rows, columns
βœ” Run your first query (SELECT *)
βœ” Explore any sample database

πŸ”₯ Pro Tip
Don’t just read β†’ Try everything practically
SQL is 90% practice, 10% theory

Double Tap ❀️ For More
❀42
In a table, what does a β€œrow” represent?
Anonymous Quiz
12%
A. A column name
74%
B. A single record
7%
C. A database
7%
D. A query
❀2
Which of the following is an example of a relational database?
Anonymous Quiz
8%
A. Excel
10%
B. MongoDB
81%
C. MySQL
1%
D. Notepad
Which SQL command is used to fetch data from a table?
Anonymous Quiz
10%
A. INSERT
1%
B. DELETE
83%
C. SELECT
6%
D. UPDATE
❀2πŸ”₯1
Now, let’s move to the next topic in SQL Roadmap

✍️ SELECT WHERE

This is the most important beginner topic πŸ‘‡

🧠 1. SELECT Statement

β€’ SELECT is used to retrieve data from a table

πŸ‘‰ Basic Syntax
SELECT column_name FROM table_name;

πŸ‘‰ Example
SELECT name FROM employees;

β€’ βœ” Returns only the name column

πŸ‘‰ Select Multiple Columns
SELECT name, salary FROM employees;

πŸ‘‰ Select All Columns
SELECT * FROM employees;

🎯 2. WHERE Clause (Filtering Data)

β€’ WHERE is used to filter records based on conditions

πŸ‘‰ Syntax
SELECT * FROM table_name
WHERE condition;

πŸ‘‰ Example
SELECT * FROM employees
WHERE salary > 50000;

βœ” Returns employees earning more than 50k

⚑ 3. Operators You Must Know

πŸ”Ή Comparison Operators
β€’ = (equal)
β€’ > (greater than)
β€’ < (less than)
β€’ >= , <=
β€’ != or <> (not equal)

πŸ”Ή Logical Operators
β€’ AND β†’ both conditions true
β€’ OR β†’ any condition true
β€’ NOT β†’ reverse condition

πŸ‘‰ Example
SELECT * FROM employees
WHERE department = 'IT' AND salary > 50000;

πŸ’‘ 4. Real-Life Thinking

Instead of memorizing, think like this:

β€’ πŸ‘‰ β€œWhat data do I need?”
β€’ πŸ‘‰ β€œFrom which table?”
β€’ πŸ‘‰ β€œWhat condition?”

Example:
β€œShow all HR employees earning less than 40k”

SELECT * FROM employees
WHERE department = 'HR' AND salary < 40000;

🎯 5. Practice Tasks
1. Show all employees with salary > 30k
2. Show employees from IT department
3. Show employees with salary between 40k–80k
4. Display only names of HR employees
5. Combine conditions using AND / OR

πŸ”₯ Practice Tasks Solution

βœ… 1. Show all employees with salary > 30k
SELECT * FROM employees
WHERE salary > 30000;

βœ… 2. Show employees from IT department
SELECT * FROM employees
WHERE department = 'IT';

βœ… 3. Show employees with salary between 40k–80k
SELECT * FROM employees
WHERE salary BETWEEN 40000 AND 80000;

β€’ πŸ‘‰ Alternative:
SELECT * FROM employees
WHERE salary >= 40000 AND salary <= 80000;

βœ… 4. Display only names of HR employees
SELECT name FROM employees
WHERE department = 'HR';

βœ… 5. Combine conditions using AND / OR
SELECT * FROM employees
WHERE department = 'IT' AND salary > 50000;

β€’ πŸ‘‰ OR example:
SELECT * FROM employees
WHERE department = 'HR' OR salary < 30000;

⚑ Double Tap ❀️ For More
1❀22πŸ‘1
What will this query return?

SELECT name FROM employees;
Anonymous Quiz
8%
A. All columns
88%
B. Only names of employees
1%
C. Only salaries
3%
D. Table structure
❀2
What does this query do?

SELECT * FROM employees WHERE department = 'HR';
Anonymous Quiz
6%
A. Shows all employees
90%
B. Shows only HR employees
2%
C. Deletes HR employees
2%
D. Updates HR employees
❀2πŸ₯°1
Which operator is used to combine multiple conditions?
Anonymous Quiz
51%
A. JOIN
43%
B. AND
4%
C. SELECT
2%
D. ORDER
❀3
Now, Let’s move to the next topic of the SQL Roadmap:

ORDER BY LIMIT

🧠 1. ORDER BY (Sorting Data)

ORDER BY is used to sort your result.

πŸ‘‰ Syntax

SELECT column_name FROM table_name
ORDER BY column_name;


πŸ”Ή Ascending Order (Default)

SELECT * FROM employees
ORDER BY salary ASC;


βœ” Lowest salary β†’ highest

πŸ”Ή Descending Order

SELECT * FROM employees
ORDER BY salary DESC;


βœ” Highest salary β†’ lowest

πŸ’‘ 2. Sorting Multiple Columns

SELECT * FROM employees
ORDER BY department ASC, salary DESC;


πŸ‘‰ First sorts by department
πŸ‘‰ Then salary within each department

🎯 3. LIMIT (Control Output Size)

LIMIT is used to restrict the number of rows.

πŸ‘‰ Syntax

SELECT * FROM table_name
LIMIT number;


πŸ‘‰ Example

SELECT * FROM employees
LIMIT 5;


βœ” Returns only the first 5 rows

⚑ 4. Using ORDER BY LIMIT

πŸ‘‰ Top 5 highest salaries

SELECT * FROM employees
ORDER BY salary DESC
LIMIT 5;


πŸ‘‰ Lowest 3 salaries

SELECT * FROM employees
ORDER BY salary ASC
LIMIT 3;


🎯 5. Practice Tasks
1. Show all employees sorted by salary (ascending)
2. Show all employees sorted by salary (descending)
3. Get top 3 highest paid employees
4. Get lowest 2 salary employees
5. Sort employees by department and salary

βœ… Practice Task Solution

βœ… 1. Show all employees sorted by salary (ascending)

SELECT * FROM employees
ORDER BY salary ASC;


βœ… 2. Show all employees sorted by salary (descending)

SELECT * FROM employees
ORDER BY salary DESC;


βœ… 3. Get top 3 highest paid employees

SELECT * FROM employees
ORDER BY salary DESC
LIMIT 3;


βœ… 4. Get lowest 2 salary employees

SELECT * FROM employees
ORDER BY salary ASC
LIMIT 2;


βœ… 5. Sort employees by department and salary

SELECT * FROM employees
ORDER BY department ASC, salary DESC;


πŸ‘‰ First sorts by department
πŸ‘‰ Then highest salary inside each department

⚑ Mini Challenge πŸ”₯

πŸ‘‰ Get the 2nd highest salary employee.

⚑ Mini Challenge Solution πŸ”₯

βœ” Method 1 (Using LIMIT + OFFSET)

SELECT * FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 1;


βœ” Method 2 (Alternative way)

SELECT * FROM employees
ORDER BY salary DESC
LIMIT 1, 1;


πŸ”₯ Pro Tip:
If you understand OFFSET β†’ you can get Top N, 2nd highest, 3rd highest easily.

⚑ Double Tap ❀️ For More
❀24