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



See all the Success Stories - here
Testimonials - here


You can check out other TakeOff Talent offerings that have helped 7,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

UnitedHealth Group is hiring for a fresher entry level Data Analyst role in India

Position: Data Analyst Company: UnitedHealth Group (Optum) Location: Noida, Uttar Pradesh, India Job Type: Full-time Job Mode: Onsite Job Requisition ID: 2324896 Years of Experience: 0–3 years Company Description UnitedHealth Group (UHG) is a global leader in health care innovation and management, dedicated to improving how the health system works for everyone. It operates through two main entities, Optum and UnitedHealthcare, both focused on integrating advanced data solutions, technology, and care delivery. The company’s mission revolves around simplifying health care delivery, improving outcomes, and creating affordable and accessible services for millions of individuals. UHG combines analytical expertise, medical knowledge, and technology to identify opportunities for improvement in patient care and health management. Employees at Optum, the data and technology arm of UHG, are empowered to make a measurable difference through impactful projects that af...

Novartis is hiring for a fresher entry level Data Scientist role in India

Position: Data Scientist Company: Novartis Healthcare Private Limited Location: Hyderabad, India Job type: Full-time Job mode: Onsite Job requisition id: REQ-10030031 Years of experience: 0–3 years Company Description Novartis is one of the world’s leading healthcare companies, dedicated to reimagining medicine to improve and extend people’s lives. The organization focuses on creating innovative solutions that address some of the most challenging health conditions, with an emphasis on scientific excellence and advanced technology. It operates in more than 150 countries, with a workforce committed to transforming patient care and access to healthcare solutions. In India, Novartis Healthcare Private Limited supports global operations, contributing to research, development, analytics, and digital transformation across various therapeutic areas. The company fosters an inclusive, collaborative culture that encourages innovation, team...

General Mills is hiring for a fresher entry level Data Analyst – Business Intelligence role in India

Position: Data Analyst – Business Intelligence, GIC SC Analytics Company: General Mills Location: Mumbai, India Job type: Full-time Job mode: Hybrid Job requisition id: 35057 Years of experience: 0–1.5 years Company Description General Mills is one of the world’s largest food companies with a legacy of over 150 years. The organization is known for iconic brands such as Cheerios, Pillsbury, Betty Crocker, Nature Valley, and Häagen-Dazs. Operating across 100 countries and six continents, General Mills continues to grow as an innovation-driven company that values both tradition and progress. The company’s operations in India are managed through the General Mills India Center (GIC) based in Mumbai, which functions as the global shared services hub. The GIC supports multiple areas including Supply Chain, Finance, HR, Digital & Technology, Consumer Insights, Sales, and Enterprise Business Services. The center employs over 1,800 professionals and focuses on de...

EXL is hiring for a fresher entry level Data Analyst role in India

Position: Data Analyst - Application Development - Data Visualization Company: EXL Location: Gurugram, Haryana, India Job type: Full-time Job mode: Onsite Job requisition id: Not disclosed Years of experience: 0-3 years Company Description EXL is a global leader in analytics, digital transformation, and business process management, empowering organizations to make smarter decisions using data-driven strategies. The company blends advanced analytics, automation, AI, cloud technologies, and industry-specific expertise to help businesses reimagine operations and achieve sustainable growth. With a workforce of over 47,000 professionals across more than 30 countries, EXL partners with clients in industries such as insurance, healthcare, banking, logistics, and retail. The company’s culture emphasizes continuous innovation, collaboration, and client-centricity, where every solution is tailored to suit unique business challenges. EXL believes that meaningful tran...

American Express is hiring for a fresher entry level Data Analyst role in India

Position: Analyst - Data Analytics Company: American Express Location: Gurugram, Haryana, India Job Type: Full-time Job Mode: Hybrid Job Requisition ID: 25019316 Years of Experience: 0-3 years Company Description American Express, a global financial services leader, has built its legacy on over 175 years of trust, innovation, and customer-centric excellence. The organization serves millions of customers worldwide by offering cutting-edge payment solutions, financial services, and data-driven insights that empower businesses and individuals. Its culture is defined by shared values, collaboration, and a strong sense of leadership that prioritizes inclusion, integrity, and growth. Employees at American Express are encouraged to bring their ideas to life, contribute meaningfully, and innovate with purpose. The company emphasizes holistic well-being by offering benefits that support physical, mental, and financial health, ensuring every employee can thrive pers...

Turing is hiring for a fresher entry level Data Scientist role in India

Position: Data Scientist Company: Turing Location: India Job type: Contract assignment Job mode: Remote work Job requisition id: 17843 Years of experience: Open to freshers and early career professionals Candidates with zero to three years of experience can apply Company description Turing is an international company that focuses on artificial intelligence and data focused solutions for global clients The company develops advanced systems and digital products that support automation, structured decision making and intelligent processing Turing supports leading research teams and enterprise clients in the design and maintenance of intelligent systems that handle model training, reasoning, coding tasks, multilingual processing and agent based execution The company works with many well known technology organizations and delivers solutions for building and improving large models Turing maintains a large network of engineering and...

myKaarma is hiring for a fresher entry level Data Analyst role in India

Position: Data Analyst Focus on turning complex information into clear, useful insights Supports product and business users with analytical solutions Works closely with multiple teams to build clarity around product performance and customer behavior Helps improve decision making by providing accurate data Company: myKaarma Provides software solutions for dealership service centers Uses communication, scheduling, and digital payment tools in one platform Brings ease and simplicity to interactions between dealership teams and customers Inspired by principles of efficiency used in world class production systems Encourages innovation and continuous learning Aims to improve the entire service experience in the automotive world Location: Noida, Uttar Pradesh, India Hybrid working structure with a mix of office and home based work Job type: Full time role Requires active involvement with teams Expected to support business on ongoing ...

TransUnion is hiring for a fresher entry level Data Analyst role in India

Position: Data Analyst Company: TransUnion Location: Hyderabad, India Job type: Full time Job mode: Hybrid Job requisition id: 19037960 Years of experience: 1 year of experience in SQL, etc. (it can be your personal, project experience as well , not mandatory a full time job experience) Company description TransUnion operates as a global information and insights company with thousands of employees across many countries. The organization focuses on helping individuals and businesses make decisions backed by data. Its work involves providing accurate and reliable data so that transactions can happen with confidence. The company uses technology, data management approaches, and digital platforms to expand its offerings. TransUnion aims to ensure that every individual is represented in the data world in a fair manner. The company works in various domains related to credit, fraud prevention, analytics, risk assessment, and marketin...

Ford Motor Company is hiring for a fresher entry level AI Data Scientist role in India

Position: AI Data Scientist Company: Ford Motor Company Location: Chennai, Tamil Nadu, India Job type: Full-time Job mode: Hybrid Job requisition id: 54097 Years of experience: 0–3 years Company Description Ford Motor Company is a global leader in mobility, technology, and innovation, operating in more than 100 countries with a mission to shape the future of transportation. The company integrates advanced data, analytics, and artificial intelligence to design next-generation vehicles and digital experiences. Ford’s technology and enterprise teams work together to build safe, efficient, and intelligent mobility systems, driving digital transformation in every area of the business. The organization fosters a culture of learning, collaboration, and integrity, empowering individuals to innovate and contribute to solving complex global challenges. With a commitment to sustainability, Ford invests in electric mobility, AI-driven automation, and cybersecurity, en...

Bain & Company is hiring for a fresher entry level Analyst role in India

Position: Analyst (Batch 2025) [As per JD looks more of a Market Research Analyst role] Company: Bain & Company Location: Gurugram, Haryana, India Job type: Full-time Job mode: Hybrid Job requisition id: Not explicitly provided by the company Years of experience: 0–1 year Company description Bain & Company is a world-renowned management consulting firm with a strong focus on helping ambitious leaders and organizations shape the future in meaningful ways. Since its establishment in 1973, Bain has been working closely with global clients to deliver impactful and sustainable business transformations. Operating in more than 65 cities across 40 countries, the company partners with organizations from multiple industries, including consumer products, retail, financial services, healthcare, and technology. The firm’s approach is rooted in deep collaboration, working as a single integrated team with clients, aiming to achieve measurable, lasting outcomes...