Skip to main content

SQL Interview Question - 1


Consider a table named Employee with the following schema:
CREATE TABLE Employee (
    emp_id INT PRIMARY KEY,
    emp_name VARCHAR(100),
    department VARCHAR(100),
    salary DECIMAL(10, 2),
    hire_date DATE
);

Write an SQL query to find the employee(s) with the highest salary within each department.

Sample Table:


emp_id emp_name department salary hire_date
1 Alice Sales 50000 2020-01-01
2 Bob Sales 55000 2019-05-15
3 Charlie HR 60000 2020-03-20
4 David HR 58000 2018-11-10
5 Emma Marketing 52000 2021-02-28
6 Frank Marketing 53000 2019-08-10

Solution:

SELECT 
    emp_id,
    emp_name,
    department,
    salary
FROM 
    Employee e
WHERE 
    (department, salary) IN (
        SELECT 
            department,
            MAX(salary)
        FROM 
            Employee
        GROUP BY 
            department
    );

 

Explanation:

  • The inner query (SELECT department, MAX(salary) FROM Employee GROUP BY department) finds the maximum salary for each department.
  • The outer query selects all rows from the Employee table where the (department, salary) tuple matches those found by the inner query.
  • This effectively retrieves the employee(s) with the highest salary within each department.

Share your alternate solution in comments.


Check our offerings below!


Success Stories

Real outcomes from learners who followed the process



See all the Success Stories - here
Testimonials - here


You can check out other TakeOff Talent offerings that have helped 8,000+ people land jobs.

Offerings
📄 CV Review
📘 200 most-asked SQL interview questions with detailed solutions
📘 200 most-asked Python interview questions with detailed solutions
📊 SQL Crash Course
✍️ CV Writing for freshers
✍️ CV Writing
🛠️ Portfolio Project
🗣️ English Speaking Practice (Live 1:1)
🎯 Job Search Mentorship Package

  In case of any questions around services above, write to us at vibhanshu@takeofftalent.com

  Connect with our founder on Linkedin - https://www.linkedin.com/in/vibvibgyor/



Video Gallery



Check more videos here>>

Other popular job openings

PhonePe is hiring for an entry level Associate Business Analyst role in India

Position: Associate Business Analyst (SRA) Company: PhonePe Limited Location: Bengaluru, Karnataka, India Job type: Full-time Job mode: Onsite Job requisition id: Not specified Years of experience: 0.5+ years (relevant internship is counted) Company description PhonePe Limited, previously known as PhonePe Private Limited, stands as India's leading fintech enterprise dedicated to building advanced digital platforms across payments, distribution services, and financial solutions. Launched in 2016 and headquartered in Bengaluru, India, the company has scaled exponentially to become an integral component of the national payment infrastructure. As of April 2026, PhonePe serves more than 70 Crore life-till-date registered users and maintains an expansive merchant acceptance network spanning over 5 Crore business partners. The company’s portfolio encompasses Consumer Payments, Merchant Payments, Lending, Insurance Distribution, Share. Market (stock broking and mutual funds plat...

Trinity Lifesciences is hiring for an FRESHER entry level Associate, Forecasting (Data Analyst / Data Scientist) role in India

Position Associate, Forecasting (Data Analyst / Data Scientist)  Company Trinity Life Sciences Location Bangalore, India Job type Full-time Job mode Onsite Job requisition id JR100873 Years of experience 0-2 years Company description Trinity Life Sciences is an established leader in global life sciences commercialization strategy, fusing human intelligence with innovative artificial intelligence solutions. For over three decades, the company has partnered with top-tier pharmaceutical, biotechnology, and medical technology enterprises worldwide. Trinity delivers end-to-end strategic clarity and data-driven confidence across every stage of the product life cycle, from early pre-launch discovery to full-scale commercialization and loss of exclusivity. The organization leverages deep therapeutic domain expertise alongside cutting-edge, purpose-built technology platforms to drive impactful business outcomes. Trinity enables global clients to execute high-impact market entry stra...

Solstice Advanced Materials is hiring for an FRESHER entry level Data Analyst role

Position: Data Analyst Company: Solstice Advanced Materials Location: 4th floor, WeWork, Amanora Town Centre, Amanora Park Town, Hadapsar, Pune, Maharashtra, 411028, IN Job type: Full-time Job mode: Hybrid Job requisition id: 108113 Years of experience: 0-3 years Company Description Solstice Advanced Materials is a globally recognized pioneer in high-performance materials, fluorine products, industrial chemicals, and sustainable technology solutions. Operating with a legacy rooted in advanced chemical engineering and high-tech manufacturing, the organization focuses on driving low-global-warming transitions across industries. The company designs, tests, and manufactures next-generation refrigerants, blown agents, industrial solvents, and critical specialty components used in electronics, automotive, and aerospace sectors. With world-class manufacturing plants, specialized R&D facilities, and global commercial offices, Solstice Advanced Materials powers sustainable pro...

IDFC FIRST Bank is hiring for an FRESHER entry level Business Analyst role in India

Position: Business Analyst - UPI Company: IDFC FIRST Bank Location: Navi Mumbai, Maharashtra, India Job type: Full-time Job mode: Onsite Job requisition id: P-206425 Years of experience: 0 to 3 years (with 2-3 project experience) Company description IDFC FIRST Bank is a premier, customer-focused private sector banking enterprise in India, dedicated to delivering modern, technology-driven financial solutions. Operating with a strong purpose to drive meaningful social and economic impact, the institution seamlessly merges traditional banking excellence with modern digital infrastructure. The organisation provides an innovative environment for professionals, emphasizing continuous growth, leadership excellence, and cut-through software capabilities. Through initiatives like TechNEXT and various transformative digital roadmaps, the bank focuses heavily on high-scale transactional ecosystems, real-time payment processing, and resilient backend networks. The bank serves millions of retail an...

Blue Matter Consulting is hiring for an FRESHER entry level Analytics Associate (Analyst) role in India

Position: Analytics Associate (Analyst) Company: Blue Matter Consulting Location: Gurgaon and Pune, India Job type: Full-time Job mode: Onsite Job requisition id: Not Specified in the original JD Years of experience: 0 to 2 years Company description Blue Matter Consulting operates as a rapidly expanding boutique management consultancy specializing in global strategy and decision-support services for the biopharmaceutical and life sciences sectors. The firm collaborates closely with major biotechnology, pharmaceutical, and healthcare organizations to streamline the commercialization of life-changing therapies and improve overall global human health. Operationally headquartered across eight major worldwide hubs—including Gurgaon, Mumbai, Pune, Zurich, London, Berlin, New York, and San Francisco—the organization fosters a global perspective and continuous inter-office synergy. Driven by an entrepreneurial operating ethos, the company emphasizes personal accountability, intellec...

QBYSS is hiring for an FRESHER entry level REMOTE Data Analyst role in India

Position: Data Analyst Company: QBYSS Location: India Job type: Full-time Job mode: Remote Job requisition id: Not Specified in the original JD Years of experience: 0-2 years (Fresher / Entry Level) Company description QBYSS is a pioneering UK-based technology firm specializing in revolutionary power conversion innovations. The company actively focuses on transforming traditional, legacy power architectures into fully programmable, software-defined solutions. By combining cutting-edge digital power software with advanced hardware electronics, QBYSS delivers real-time power control systems. Their state-of-the-art power conversion technologies optimize electrical efficiency while substantially lowering operational energy waste. QBYSS operates across a wide spectrum of sectors including commercial electronics, medical devices, military applications, and data infrastructure. Their proprietary digital power architecture delivers ultra-high energy efficiency, superior reliability, an...

Kulfi Collective is hiring for an FRESHER entry level Associate - Social Media Data Analytics role in India

Position: Associate - Social Media Analytics Company: Kulfi Collective Location: Worli, Mumbai Job type: Full-Time Job mode: Hybrid Job requisition id: Not Specified in the original JD Years of experience: Entry-Level / 0 to 3 Years Company Description Kulfi Collective stands at the vibrant intersection of modern storytelling, cutting-edge technology, and contemporary culture. We operate as a forward-thinking creative network and digital content studio dedicated to crafting meaningful media experiences. Our primary objective is to conceive, design, and produce both original intellectual properties and high-impact branded content. We build custom narrative strategies specifically tailored to capture the imagination of Generation Y and Generation Z audiences. Our multidisciplinary team is composed of creative storytellers, digital strategists, technologists, and cultural enthusiasts who are deeply passionate about digital innovation. We firmly believe in the transformative capabil...

TEOCO is hiring for an FRESHER entry level Data Engineer role in India

Position Data Engineer Position Title Data Engineer Company TEOCO Corporation Location Bangalore, India Job Type Full-time Job Mode Hybrid Job Requisition ID Not Specified in the original JD (N/A) Years of Experience 0 to 3 Years (Fresher / Entry-Level) Company Description TEOCO Corporation is a leading global provider of analytics, assurance, and optimization solutions designed specifically for telecommunications service providers. The company enables communications service providers (CSPs) worldwide to manage network performance, optimize infrastructure efficiency, streamline operational workflows, and maximize profitability. TEOCO’s extensive suite of software offerings spans revenue assurance, financial analytics, network planning, network optimization, service assurance, and fraud management. Serving over 300 communication service providers and network operators across more than 100 countries, TEOCO plays a pivotal role in maintaining the integrity of complex telecom ecosystems. T...

Wipro Limited is hiring for an FRESHER entry level MIS Executive L1 role in India

Position MIS EXECUTIVE L1 Company Wipro Limited Location Mumbai, Maharashtra, India Job type Full-time Job mode Onsite Job requisition id Not specified in the original job description Years of experience 0 to 3 years Company description Wipro Limited (NYSE: WIT, BSE: 507685, NSE: WIPRO) is a premier global technology services and consulting enterprise dedicated to orchestrating innovative digital transformation solutions. The organization builds comprehensive capabilities spanning strategic consulting, user-centric design, complex system engineering, and continuous business operations. Wipro empowers enterprise clients across international markets to achieve ambitious digital roadmaps and sustain resilient operational growth models. With an expansive global workforce exceeding 230, 000 employees and strategic partners across 65 nations, Wipro delivers impactful solutions for businesses, professionals, and communities. The company maintains a strong market footprint by inte...

Deloitte is hiring for an FRESHER entry level Data Analyst role in India

Position Data Analyst Company Deloitte Shared Services India LLP Location Delhi / NCR, India Job type Full-time Job mode Hybrid Job requisition id 112709 Years of experience 0 to 3 years (Freshers / Entry Level) Company description Deloitte operates as a prominent global professional services network, delivering world-class audit, consulting, financial advisory, risk advisory, tax, and operational intelligence services across hundreds of territories. Within this global umbrella, Deloitte Shared Services India LLP serves as an indispensable engine driving strategic growth, operational excellence, organizational transformation, and analytical rigor for internal leadership and cross-functional practices. The organization is built around a steadfast commitment to high ethical standards, continuous innovation, inclusive leadership, and sustained value creation. By bringing together diverse multi-disciplinary professionals, Deloitte fosters an energetic environment where cutting-edge analyti...