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

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

Position Role Title: Reporting Data Analyst [People & Organization (P&O) Reporting Analyst] responsible for driving enterprise workforce analytics, data extraction, and human capital reporting excellence. Primary Function: Operating within the Human Resources and P&O division to deliver comprehensive data solutions, operational reports, and strategic insights that empower organizational decision-making. Career Level: Entry-level position specifically designed for fresh graduates and early-career professionals eager to build a robust foundation in corporate HR analytics and enterprise data management. Company Enterprise Name: Sandoz Group AG, a globally recognized leader and pioneer in the generic and biosimilar medicines sector. Industry Focus: Pharmaceutical manufacturing, biotechnology, healthcare solutions, and sustainable access medicine. Global Reach: Delivering hundreds of millions of patient treatments annually across more than one hundred countries worldwide, reinf...

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

Position: Associate Data Analyst (Technical) Serving as a foundational technical catalyst within a specialized data intelligence vertical operating directly within the Google account ecosystem. Designed specifically for early-career professionals and freshers eager to establish a robust, long-term trajectory in modern data analytics without requiring an advanced technical background at the onset. Positioned at the intersection of operational data management, research, validation, and emerging artificial intelligence workflows. Encompassing a dynamic scope of responsibilities that evolve organically from administrative data handling to advanced analytical, database-focused, and automation-driven engineering tasks. Operating in close synergy with seasoned software developers, product managers, and multidisciplinary global teams to handle large-scale, complex datasets. Company: QualityAI Recognized globally as a premier, industry-leading AI-first quality engineering enterprise that transf...

Schneider Electric is hiring for an FRESHER entry level Data Analyst I role in India

Position:  Data Analyst I  Company: Schneider Electric  Location: Gurgaon, India  Job type: Full-time  Job mode: Hybrid  Job requisition id: 135810  Years of experience: 0-3 years / Junior candidates welcome Company description Schneider Electric operates as a global leader in energy management and digital automation, delivering comprehensive solutions across homes, infrastructure, data centers, buildings, and diverse industries. The corporate organization combines cutting-edge energy technologies, real-time automation, software, and consulting services to empower enterprise clients to transform ambitious sustainability, energy efficiency, and digitalization objectives into tangible, measurable outcomes. Achieving approximately €40 billion in global revenue with over 9% organic growth, the organization employs more than 150, 000 individuals operating across more than 100 countries globally. The foundational corporate culture centers ...

Barclays is hiring for an FRESHER entry level Reporting and Visualization Data Analyst role in India

Position: Reporting and Visualization Data Analyst Company: Barclays Location: Pune, India Job Type: Permanent Job Mode: Hybrid Job Requisition ID: JR-0000123322 Years of Experience: 0-3 Years Company Description Barclays stands as a premier global financial institution with a rich heritage spanning over three centuries, delivering comprehensive services in personal banking, credit cards, corporate and investment banking, and wealth management to millions of clients worldwide. The organization operates on an international scale, committed to responsible finance, sustainable economic growth, and ethical business practices that support individuals, businesses, and communities for the long term. The Barclays campus in Pune serves as the largest operational and technological hub outside of the bank's global headquarters in London, acting as a center of excellence for worldwide business functions. Housing thousands of dynamic professionals across Operations, Technology, and corporate Fu...

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

Position Junior Data Analyst This role serves as a foundational position designed for individuals eager to build a robust professional trajectory in financial data analysis, corporate governance, and market research. The incumbent will directly contribute to compiling, verifying, and maintaining critical corporate information supporting global institutional investors and market participants. Company The hiring organization is Institutional Shareholder Services (ISS), globally recognized as a premier provider of corporate governance and responsible investment solutions. Operating alongside its broader corporate ecosystem including ISS STOXX and subsidiary ISS Corporate Solutions (ICS), the firm empowers capital market participants worldwide. The enterprise leverages decades of accumulated industry expertise, cutting-edge analytical tools, and comprehensive data sets to deliver objective research and recommendations. Location Mumbai, India Job Type The employment arrangement is structure...

Amazon is hiring for a FRESHER entry level Applied Data Scientist I role in India

Position: Applied Data Scientist I Company: Amazon Location: Hyderabad, India Job type: Full-time Job mode: Onsite Job requisition id: 10565196 Years of experience: 0-3 years Company description Amazon is a world-renowned technology company and global e-commerce leader dedicated to customer-obsessed scientific innovation and large-scale engineering. Driven by the core philosophy that continuous research and cutting-edge discovery are vital to remaining the world's most customer-centric organization, Amazon provides an ecosystem where world-class talent thrives. Through Amazon Science, thousands of researchers and software practitioners collaborate to solve complex real-world operational challenges using artificial intelligence, machine learning, computer vision, natural language processing, and advanced robotics. Amazon fosters an inclusive, supportive workplace culture where scientific rigor, continuous peer learning, academic publishing, and operational deployment go...

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

Position: Associate Business Analyst Company: EXL Location: Gurugram, Haryana, India Job type: Full-time Job mode: On-site Job requisition id: Not specified Years of experience: 0-3 years Company description EXL stands as a leading global partner in business consulting and services with a strong focus on data-driven transformation. The organization specializes in helping clients evolve through analytics, digital interventions, and operations management. Collaboration forms the core of EXL’s approach, built on continuous listening and learning to adapt methodologies. Solutions are tailored to unique client needs, culture, goals, and existing legacy data and technology environments. EXL avoids unrealistic overhauls and generic off-the-shelf products that overlook individual business contexts. The company positions itself as a business evolution partner that maximizes the value of data for better decisions. Expertise spans transformation, data science, and change management...

American Express is hiring for an FRESHER entry level Analyst Data Science role in India

Position: Analyst Data Science Company: American Express Location: Gurugram and Bengaluru, India Job type: Full time Job mode: Hybrid Job requisition id: 26014259 Years of experience: 0-30 months Company description American Express stands as a globally recognized leader in financial services with a rich legacy spanning over 175 years of continuous innovation and customer-centric excellence. The organization operates at the forefront of payments, credit, and risk management, empowering millions of customers and businesses worldwide through trusted products and seamless experiences. Credit and Fraud Risk (CFR) forms a critical pillar within the company, dedicated to driving sustainable and profitable growth by minimizing fraud exposure and sustaining some of the industry’s lowest credit loss rates. Through advanced tools, evolving technology, and sophisticated analytics, the CFR team detects fraudulent activities early, protects legitimate spending patterns, and delivers ...

Hewlett Packard Enterprise is hiring for an FRESHER entry level Data Scientist role in India

Position: Data Scientist Company: Hewlett Packard Enterprise (HPE) Location: Bengaluru, Karnataka, India Job type: Full-time Job mode: Onsite Job requisition id:  Not provided in the original JD Years of experience: 0-3 years (Entry Level) Company description Hewlett Packard Enterprise is a prominent global technology vendor operating extensively in edge-to-cloud solutions. The organisation dedicatedly assists enterprise customers in seamlessly connecting, protecting, analysing, and acting on complex datasets across diverse digital landscapes. The corporate culture thrives on innovation, operational agility, and continually pioneering superior methods to accelerate technology transformation. HPE strongly values diverse employee backgrounds, foster flexible work environments, and consistently aim to operate as a unified global force for good. Team members are actively encouraged to stretch their professional skill sets, push boundaries, and grow their careers within an support...

Swiggy is hiring a Machine Learning Engineer (0-1 yrs exp)

Position: Title : Machine Learning Engineer - I (DSP) Company: Name : Swiggy Location: City : Bangalore State : Karnataka Country : India Job Type: Type : Full-time Job Mode: Mode : Remote Job Requisition ID: ID : Not specified Years of Experience: Required Experience : 0-1 years Company Description Swiggy is one of India's largest and leading on-demand delivery platforms. The company adopts a tech-first approach, focusing on logistics and developing solutions to meet consumer demands. Swiggy operates in 500 cities across India , partnering with hundreds of thousands of restaurants. It has a large employee base of over 5000 employees and a 2 lakh+ strong fleet of independent delivery executives. The company leverages cutting-edge machine learning (ML) technology and processes terabytes of data every day to offer seamless and fast delivery experiences to millions of customers. Since its inception in 2014 , Swiggy has grown from a hyperlocal food delivery service to a logistics h...