TGViewer
Channel Public Channel
Data Analytics

Data Analytics

@sqlspecialist

Perfect channel to learn Data Analytics

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

For Promotions: @coderfun @love_data
Subscribers
111K
Photos
224
Videos
1
Links
951

Showing posts older than #2920 · Back to latest

Older Posts 20 shown
Post #2918 4.57K
☁️ 𝗞𝗶𝗰𝗸𝘀𝘁𝗮𝗿𝘁 𝗬𝗼𝘂𝗿 𝗔𝗪𝗦 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 | 𝗙𝗥𝗘𝗘 𝗔𝗪𝗦 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗖𝗼𝘂𝗿𝘀𝗲𝘀🚀

✔️ High-Demand Cloud Skills
✔️ Prepare for AWS Certifications
✔️ Strengthen Your Resume & LinkedIn
✔️ Unlock Opportunities in Cloud, AI & DevOps

🔗 𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:

https://pdlinks.in/ed7

🚀 Start Learning Today. Build Cloud Skills. Accelerate Your Tech Career!
  • ❤ 2
Post #2917 5.2K
Want to become a pro in Data Analytics and crack interviews?

Focus on these key topics: 👇

1) Understand Data Analytics basics & tools
2) Learn Excel for data cleaning & analysis
3) Master SQL for data querying
4) Study data visualization principles
5) Get hands-on with Power BI/Tableau dashboards
6) Explore statistics & probability fundamentals
7) Learn data wrangling and preprocessing
8) Understand data storytelling and report writing
9) Practice hypothesis testing & A/B testing
10) Get familiar with Python/R for analytics (optional but helpful)
11) Work on real datasets and case studies (Kaggle is great)
12) Build end-to-end projects from data collection to visualization
13) Learn how to communicate insights effectively
14) Practice problem-solving with datasets regularly
15) Optimize your resume with analytics keywords
16) Follow analytics experts and tutorials on YouTube/LinkedIn

Pro tip: Search each topic on YouTube and watch short 10-15 min videos. Practice alongside to build strong fundamentals.

17) Finally, watch full data analytics project walkthroughs and try them yourself.
18) Learn integration of SQL and Power BI/Tableau for advanced reporting.

Credits: https://t.me/sqlspecialist

React ❤️ for more
  • ❤ 17
Post #2916 4.63K
🚀 𝗚𝗼𝗼𝗴𝗹𝗲 𝗙𝗥𝗘𝗘 𝗔𝗜 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝗪𝗶𝘁𝗵 𝗖𝗼𝗺𝗽𝗹𝗲𝘁𝗶𝗼𝗻 𝗕𝗮𝗱𝗴𝗲𝘀 🔥

Google is offering free AI courses with completion badges to help students & professionals build in-demand AI skills 🌍

✨ Learn from Google Experts
✨ Earn Google Completion Badges
✨ Boost Your Resume & LinkedIn Profile
✨ Build In-Demand AI Skills for 2026

🔗 𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:

https://pdlink.in/49lCYxa

🔥 Start your AI journey today and future-proof your career with Google AI learning programs.
  • ❤ 3
Post #2915 4.83K
𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:
You have 2 minutes to solve this SQL query.
Find the departments where the average salary is greater than the company's overall average salary.

𝗠𝗲: Challenge accepted! 💪
SELECT
department,
AVG(salary) AS average_salary
FROM employees
GROUP BY department
HAVING AVG(salary) > (
SELECT AVG(salary)
FROM employees
);

💡 Explanation:
The query compares each department's average salary with the company's overall average salary.

• GROUP BY department calculates the average salary for each department.
• The subquery computes the overall average salary across all employees.
• HAVING filters only those departments whose average salary exceeds the company average.

This question tests your understanding of:
✅ GROUP BY
✅ HAVING
✅ Aggregate Functions AVG
✅ Subqueries

🎯 Expected Output Example
Department: Average Salary
IT: 88,500
Finance: 84,000

HR is excluded because its average salary is below the company average.

🚀 Alternative Using a Common Table Expression CTE
WITH company_avg AS (
SELECT AVG(salary) AS avg_salary
FROM employees
)
SELECT
department,
AVG(salary) AS average_salary
FROM employees, company_avg
GROUP BY department, company_avg.avg_salary
HAVING AVG(salary) > company_avg.avg_salary;

Using a CTE can improve readability, especially when the same calculated value is reused in larger queries.

🚀 Tip for SQL Job Seekers:
Interviewers often ask questions that compare group-level aggregates with overall aggregates. Master the use of HAVING with subqueries—it’s a key SQL pattern.

❤️ React with ❤️ for more SQL interview challenges!
  • ❤ 12
Post #2914 4.14K
𝗕𝗼𝗼𝘀𝘁 𝗬𝗼𝘂𝗿 𝗖𝗮𝗿𝗲𝗲𝗿 𝐖𝐢𝐭𝐡 𝗙𝗥𝗘𝗘 𝗖𝗶𝘀𝗰𝗼 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 + 𝗦𝗵𝗼𝘄𝗰𝗮𝘀𝗲 𝗗𝗶𝗴𝗶𝘁𝗮𝗹 𝗕𝗮𝗱𝗴𝗲𝘀

💫Stand out in the job market with globally recognized tech skills

✅ 100% FREE Learning
✅ Official Cisco Digital Badges
✅ Self-Paced Online Courses
✅ Beginner-Friendly Content
✅ Hands-on Labs (Selected Courses)
✅ Globally Recognized Skills

🔗 𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:

https://pdlink.in/4y0ACOI

🚀 Start Learning Today. Earn Official Cisco Badges. Get Career Ready!
  • ❤ 4
Post #2913 4.48K
🐶 ASO Corgi — platform for the App Store developers.
Find the keywords your apps and competitors rank for, and track positions across every country in one place.
🔑 Keyword research: by topic, by your app's languages, from App Store suggestions, by competitors, and with AI analysis.
• Rankings by country — history, charts, demand score (0–100)
• Global search across any App Store storefront
• ASO assistant builds your listing for each locale
• App Store top charts for any country

🎁 14 days of Pro, free 👇 (no card required)
https://asocorgi.com/?promo=promo14&utm_source=sqlspecialist&utm_medium=telegram&utm_campaign=launch
  • ❤ 5
Post #2911 5.08K
𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:
You have 2 minutes to solve this SQL query.
Find all employees who have the same manager.

Assume the table structure:
employees(employee_id, employee_name, manager_id)

𝗠𝗲: Challenge accepted! 💪

SELECT
e.employee_id,
e.employee_name,
e.manager_id,
m.employee_name AS manager_name
FROM employees e
JOIN employees m
ON e.manager_id = m.employee_id
WHERE e.manager_id IN (
SELECT manager_id
FROM employees
WHERE manager_id IS NOT NULL
GROUP BY manager_id
HAVING COUNT(*) > 1
)
ORDER BY e.manager_id, e.employee_name;

💡 Explanation:
This query identifies managers who supervise more than one employee and returns all employees reporting to those managers.

✅ The subquery groups records by manager_id.

✅ HAVING COUNT(*) > 1 finds managers with multiple direct reports.

✅ A self join retrieves the manager's name.

✅ The outer query returns every employee reporting to those managers.

This question tests your understanding of:
✅ Self Joins
✅ GROUP BY and HAVING
✅ Subqueries
✅ Organizational Hierarchies

🎯 Expected Output Example
Employee Manager
John David
Alice David
Sarah Michael
Bob Michael

🚀 Alternative Using Window Functions
SELECT
employee_id,
employee_name,
manager_id
FROM (
SELECT
*,
COUNT(*) OVER (
PARTITION BY manager_id
) AS team_size
FROM employees
WHERE manager_id IS NOT NULL
) t
WHERE team_size > 1;

This approach uses a window function to count the number of employees under each manager without using GROUP BY.

🚀 Tip for SQL Job Seekers:
Hierarchy-based questions are very common in interviews. Practice problems involving:
Employees and managers
Parent-child relationships
Organizational charts
Category trees
Recursive queries WITH RECURSIVE or recursive CTEs

❤️ React with ❤️ for more SQL interview challenges!
  • ❤ 15
Post #2909 4.91K
𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:
You have 2 minutes to solve this SQL query.

Find the customer(s) who placed the highest number of orders.

Tables:
customers(customer_id, customer_name)
orders(order_id, customer_id, order_date)

𝗠𝗲: Challenge accepted! 💪

SELECT
customer_id,
customer_name,
total_orders
FROM (
SELECT
c.customer_id,
c.customer_name,
COUNT(o.order_id) AS total_orders,
DENSE_RANK() OVER (
ORDER BY COUNT(o.order_id) DESC
) AS rnk
FROM customers c
JOIN orders o
ON c.customer_id = o.customer_id
GROUP BY
c.customer_id,
c.customer_name
) ranked
WHERE rnk = 1;


💡 Explanation:
The query first counts the total number of orders placed by each customer and then ranks them based on the order count.

✅ COUNT(o.order_id) calculates the number of orders per customer.

✅ GROUP BY ensures one row per customer.

✅ DENSE_RANK() ranks customers from highest to lowest order count.

✅ The outer query returns all customers with rnk = 1, including ties.

This question tests your understanding of:

✅ JOIN

✅ GROUP BY

✅ Aggregate Functions COUNT

✅ Window Functions DENSE_RANK

🎯 Expected Output Example

+----------+--------------+
| Customer | Total Orders |
+----------+--------------+
| John | 25 |
| Sarah | 25 |
+----------+--------------+


Both customers are returned because they are tied for the highest number of orders.

🚀 Tip for SQL Job Seekers:
Whenever an interview asks for the highest, lowest, most, or least, think about whether multiple records could tie for first place. Using DENSE_RANK() instead of LIMIT 1 makes your solution more robust and interview-ready.

❤️ React with ❤️ for more SQL interview challenges!
  • ❤ 18
Post #2907 4.74K
𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:
You have 2 minutes to solve this SQL query.

Find the employees who joined in the last 30 days.

Assume the table structure:
employees(employee_id, employee_name, department, joining_date)

𝗠𝗲: Challenge accepted! 💪

SELECT
employee_id,
employee_name,
department,
joining_date
FROM employees
WHERE joining_date >= CURRENT_DATE - INTERVAL '30 days';

💡 Explanation:
This query filters employees whose joining date falls within the last 30 days.

• CURRENT_DATE returns today's date.
• INTERVAL '30 days' subtracts 30 days from the current date.
• The WHERE clause returns employees who joined on or after that date.

This question tests your understanding of:
✅ Date Functions
✅ Date Arithmetic
✅ Filtering Records with Dates

🎯 Expected Output Example
Employee Department Joining Date
John IT 2026-06-10
Sarah HR 2026-06-22

🚀 Database-Specific Alternatives

MySQL
SELECT *
FROM employees
WHERE joining_date >= CURDATE() - INTERVAL 30 DAY;

SQL Server
SELECT *
FROM employees
WHERE joining_date >= DATEADD(DAY, -30, GETDATE());

Oracle
SELECT *
FROM employees
WHERE joining_date >= SYSDATE - 30;

🚀 Tip for SQL Job Seekers:
Date-related SQL questions are very common. Make sure you're comfortable with:
• Finding records from the last N days
• Current month/year filters
• Date differences
• Date formatting
• Database-specific date functions

❤️ React with ❤️ for more SQL interview challenges!
  • ❤ 19
Post #2904 4.94K
𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:
You have 2 minutes to solve this SQL query.

Find the third highest salary from the employees table without using LIMIT or TOP.

𝗠𝗲: Challenge accepted! 💪

SELECT
salary
FROM (
SELECT
salary,
DENSE_RANK() OVER (ORDER BY salary DESC) AS salary_rank
FROM employees
) ranked
WHERE salary_rank = 3;

💡 Explanation:
This query uses the DENSE_RANK() window function to rank distinct salary values in descending order.

• ORDER BY salary DESC assigns Rank 1 to the highest salary.
• DENSE_RANK() ensures duplicate salaries receive the same rank.
• The outer query filters for salary_rank = 3, returning the third highest distinct salary.

🎯 Expected Output Example
Salary Rank
95,000 1
90,000 2
85,000 3

Output:
Third Highest Salary
85,000

🚀 Alternative Solution Using a Correlated Subquery
SELECT DISTINCT salary
FROM employees e1
WHERE 2 = (
SELECT COUNT(DISTINCT salary)
FROM employees e2
WHERE e2.salary > e1.salary
);

This solution avoids window functions and is commonly asked to test your understanding of correlated subqueries.

🚀 Questions involving the Nth highest or Nth lowest value are interview favorites. Be comfortable solving them using:

1. DENSE_RANK()
2. RANK()
3. Correlated Subqueries
4. Common Table Expressions (CTEs)

Being able to provide multiple approaches leaves a strong impression on interviewers.

❤️ React with ❤️ for more interview challenges!
  • ❤ 17
Post #2902 4.87K
𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:
You have 2 minutes to solve this SQL query.

Find employees who earn the same salary as at least one other employee in the same department.

𝗠𝗲: Challenge accepted! 💪
SELECT
employee_id,
employee_name,
department,
salary
FROM employees
WHERE (department, salary) IN (
SELECT
department,
salary
FROM employees
GROUP BY department, salary
HAVING COUNT(*) > 1
)
ORDER BY department, salary DESC;

💡 Explanation:
The query identifies duplicate salary values within each department.

• The subquery groups records by department and salary.
• **HAVING COUNT(*) > 1** finds salary values that appear more than once in the same department.
• The outer query returns all employees whose (department, salary) matches those duplicate combinations.

This question tests your understanding of:
✅ GROUP BY
✅ HAVING
✅ Multi-column filtering
✅ Identifying duplicate records

🎯 Expected Output Example
Employee Department Salary
John IT 80,000
Alice IT 80,000
David HR 65,000
Sarah HR 65,000

🚀 Alternative Using Window Functions
SELECT
employee_id,
employee_name,
department,
salary
FROM (
SELECT
*,
COUNT(*) OVER (
PARTITION BY department, salary
) AS salary_count
FROM employees
) t
WHERE salary_count > 1;

This approach avoids a subquery with GROUP BY and is a great way to showcase your knowledge of window functions.

🚀 When interview questions ask you to find duplicates, think of these three approaches:

1. GROUP BY + HAVING
2. Window functions COUNT() OVER
3. Self Join for specific comparison scenarios

Knowing multiple solutions demonstrates strong SQL problem-solving skills.

❤️ React with ❤️ for more SQL interview challenges!
  • ❤ 11
Post #2901 4.09K
🚀 𝗡𝗩𝗜𝗗𝗜𝗔 𝗙𝗥𝗘𝗘 𝗔𝗜 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 | 𝗟𝗲𝗮𝗿𝗻 𝗙𝗿𝗼𝗺 𝗔𝗜 𝗜𝗻𝗱𝘂𝘀𝘁𝗿𝘆 𝗟𝗲𝗮𝗱𝗲𝗿𝘀

Want to build cutting-edge *AI skills* from one of the world's leading AI and GPU companies?

*NVIDIA* offers *FREE AI Certification Courses* to help students, freshers, developers, and professionals

🔗 𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:

https://pdlinks.in/nvdia

🚀 Start Learning Today. Earn Your Certificate. Build Your Future in AI!
  • ❤ 1
Post #2900 4.26K
𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:
You have 2 minutes to solve this SQL query.

Find the department with the highest average salary.

𝗠𝗲: Challenge accepted! 💪

SELECT
department,
AVG(salary) AS average_salary
FROM employees
GROUP BY department
ORDER BY average_salary DESC
LIMIT 1;

💡 Explanation:
The query calculates the average salary for each department and returns the department with the highest average salary.

• GROUP BY department groups employees by department
• AVG(salary) calculates the average salary for each department
• ORDER BY average_salary DESC sorts departments from highest to lowest average salary
• LIMIT 1 returns only the top department

This question tests your understanding of:
✅ GROUP BY
✅ Aggregate Functions AVG
✅ ORDER BY
✅ LIMIT

🎯 Expected Output
Department Average_Salary
IT 88,500

🚀 Bonus Handles Ties
If multiple departments share the highest average salary, use DENSE_RANK():

SELECT
department,
average_salary
FROM (
SELECT
department,
AVG(salary) AS average_salary,
DENSE_RANK() OVER (
ORDER BY AVG(salary) DESC
) AS rnk
FROM employees
GROUP BY department
) ranked
WHERE rnk = 1;

This version returns all departments tied for the highest average salary.

🚀 Whenever you see questions like highest, lowest, top N, or rank, think beyond LIMIT. Ask yourself: What if there's a tie? Window functions like DENSE_RANK() often provide a more complete solution.

❤️ React with ❤️ for more SQL interview challenges!
  • ❤ 15
Post #2899 4.28K
𝗧𝗖𝗦 𝗙𝗥𝗘𝗘 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗢𝗻 𝗗𝗮𝘁𝗮 𝗠𝗮𝗻𝗮𝗴𝗲𝗺𝗲𝗻𝘁 - 𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘😍

TCS iON is offering a FREE Master Data Management Course with a Certificate,

✅ 100% FREE Learning
✅ Certificate on Completion
✅ Self-Paced Online Course
✅ Beginner-Friendly Content
✅ Industry-Relevant Skills
✅ Resume & LinkedIn Profile Boost

🔗 𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:

https://pdlink.in/4jGFBw0

🚀 Start Learning Today. Upskill for Free. Get Career Ready!
  • ❤ 3
  • 👍 1
  • 🥰 1
Post #2898 4.39K
𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:
You have 2 minutes to solve this SQL query.

Find customers who have never placed an order.

Tables:

customers(customer_id, customer_name)

orders(order_id, customer_id, order_date)


𝗠𝗲: Challenge accepted! 💪

SELECT
c.customer_id,
c.customer_name
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id
WHERE o.customer_id IS NULL;

💡 Explanation:

This query uses a LEFT JOIN to return all customers, whether or not they have placed an order.

• LEFT JOIN keeps every customer in the result.
• Customers without matching records in the orders table will have NULL values.
• The WHERE o.customer_id IS NULL condition filters only customers who have never placed an order.

This question tests your understanding of:
✅ LEFT JOIN
✅ Finding missing records
✅ NULL handling

🎯 Expected Output Example

Customer ID Customer Name

105 Alice
112 David
118 Sarah


🚀 Questions about finding unmatched records are very common in interviews. Practice using:

- LEFT JOIN ... IS NULL

- NOT EXISTS

- NOT IN (carefully, because NULL values can affect results)

Among these, NOT EXISTS is often preferred for correctness and performance in many databases.

❤️ React with ❤️ for more SQL interview challenges!
  • ❤ 11
  • 🔥 1
Post #2897 4.35K
📊 𝗙𝗥𝗘𝗘 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 | 𝗡𝗼 𝗘𝘅𝗽𝗲𝗿𝗶𝗲𝗻𝗰𝗲 𝗡𝗲𝗲𝗱𝗲𝗱! 🚀

Want to start a career in Data Analytics but don't know where to begin?

These 5 FREE beginner-friendly courses will help you learn the most in-demand data skills and build a strong foundation.

🔗 𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:

https://pdlink.in/3SOk64h

🚀 Start Learning Today. Build Your Portfolio. Land Your Dream Data Job!
  • ❤ 1
Post #2896 4.7K
𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:

You have 2 minutes to solve this SQL query.

Find the top 3 highest-paid employees in each department.

𝗠𝗲: Challenge accepted! 💪

SELECT

    employee_id,

    employee_name,

    department,

    salary

FROM (

    SELECT

        employee_id,

        employee_name,

        department,

        salary,

        DENSE_RANK() OVER (

            PARTITION BY department

            ORDER BY salary DESC

        ) AS salary_rank

    FROM employees

) ranked

WHERE salary_rank <= 3

ORDER BY department, salary DESC;

💡 Explanation:

The query uses the DENSE_RANK() window function to rank employees based on salary within each department.

• PARTITION BY department creates a separate ranking for every department.

• ORDER BY salary DESC ranks the highest salary first.

• DENSE_RANK() assigns the same rank to employees with identical salaries.

• The outer query returns only employees with a rank of 3 or less.

This question tests your understanding of:

✅ Window Functions

✅ DENSE_RANK()

✅ Top N per Group

✅ Partitioning Data

🎯 Expected Output Example

Employee  Department Salary Rank

John  IT  95,000 1

Alice  IT  95,000 1

Bob  IT  90,000 2

Mike  IT  85,000 3

Sarah  HR  80,000 1

🚀 Know when to use each ranking function:

• ROW_NUMBER() → No ties (unique ranking)

• RANK() → Leaves gaps after ties

• DENSE_RANK() → No gaps after ties (ideal for Top N with ties)

❤️ React with ❤️ for more SQL interview challenges!
  • ❤ 22
Post #2895 4.65K
📊 𝗙𝗥𝗘𝗘 𝗧𝗮𝘁𝗮 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀 𝗩𝗶𝗿𝘁𝘂𝗮𝗹 𝗜𝗻𝘁𝗲𝗿𝗻𝘀𝗵𝗶𝗽 | 𝗪𝗶𝘁𝗵 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗲 🚀

Here's an amazing opportunity to complete the FREE Tata Data Analytics Virtual Internship and earn a certificate that you can showcase on your Resume and LinkedIn.

✅ 100% FREE
✅ Self-Paced & Online
✅ Beginner-Friendly
✅ Certificate on Completion
✅ Real Business Case Studies
✅ Resume & LinkedIn Boost

🔗 𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:

https://pdlink.in/4eybW8J

🚀 Upskill Today. Build Your Portfolio. Get Career Ready!
  • ❤ 9
Post #2894 5.03K
𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:
You have 2 minutes to solve this SQL query.

Find employees whose salary is higher than their manager's salary.

Assume the table structure is:

employees(employee_id, employee_name, manager_id, salary)

𝗠𝗲: Challenge accepted! 💪

SELECT
e.employee_id,
e.employee_name,
e.salary AS employee_salary,
m.employee_name AS manager_name,
m.salary AS manager_salary
FROM employees e
JOIN employees m
ON e.manager_id = m.employee_id
WHERE e.salary > m.salary;

💡 Explanation:

This query uses a self join because both employees and managers are stored in the same table.

• e represents the employee.
• m represents the manager.
• The join matches each employee with their manager using manager_id.
• The WHERE clause filters employees whose salary is greater than their manager's salary.

This question tests your understanding of:
✅ Self Joins
✅ Aliases (e and m)
✅ Comparing values across related rows

🎯 Expected Output Example

Employee Employee Salary Manager Manager Salary

John 90,000 David 80,000
Sarah 85,000 Michael 75,000


🚀 Self joins are one of the most frequently asked SQL interview topics. Practice scenarios involving employees, managers, organizational hierarchies, categories, and parent-child relationships.

❤️ React with ❤️ for more SQL interview challenges!
  • ❤ 17
Older posts →
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →