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

Indian Institute of Science (IISc) is hiring for a fresher entry level Data Science Research Associate role in India

Position: Data Science Research Associate Project-based staff role within the VISTA Lab at the Indian Institute of Science (IISc) Focus on applied machine learning, artificial intelligence, data science, and cybersecurity research Contributing to high-impact projects in the fields of automotive cybersecurity and anomaly detection for financial technology (A higher salary up to 100,000 INR per month can be offered to exceptional candidates)   Company: Indian Institute of Science (IISc) A premier institute in India for advanced research and education in science and technology Established in 1909 through the joint efforts of Jamsetji Tata, the Government of India, and the Maharaja of Mysore Globally recognized for its contributions to fundamental and applied research across multiple domains Location: Bengaluru, Karnataka, India IISc’s main campus located in North Bengaluru, spread across 400 acres State-of-the-art laboratories, research centers, and academi...

Cushman & Wakefield is hiring for an FRESHER entry level Data Analyst role in India

Position: • Data Analyst Company: • Cushman & Wakefield Location: • Gurgaon, India Job type: • Full Time Job mode: • Hybrid Job requisition id: • R-AOP-0152 Years of experience: • Not specified Company Description • Cushman & Wakefield is one of the world's leading commercial real estate services organizations, recognized for helping clients make informed decisions regarding property investments, workplace strategies, facilities management, valuation services, leasing solutions, project execution, and advisory services. • The company has built a strong reputation through decades of experience serving businesses, investors, landlords, occupiers, and developers across a broad range of industries and markets. • Operating on a global scale, the organization maintains a significant presence across numerous countries and regions, enabling clients to benefit from local market knowledge supported by international capabilities and resources. • The company employs t...

Zimmer Biomet is hiring for an FRESHER entry level Data Scientist role in India

Position: Data Scientist Company: Zimmer Biomet Location: Bangalore, Karnataka, India Job Type: Full Time Job Mode: Hybrid (3 Days in Office) Job Requisition ID: 10046 Years of Experience: 0 to 3 Years (Estimated based on role requirements) Company Description Zimmer Biomet is a globally recognized medical technology organization with a legacy spanning nearly a century. The company is dedicated to improving patient mobility and enhancing quality of life through innovative healthcare solutions. Its products and technologies are widely used across hospitals, healthcare institutions, and medical facilities around the world. The organization has established itself as a trusted leader in orthopedic and musculoskeletal healthcare technologies. Every few seconds, a patient somewhere in the world benefits from a Zimmer Biomet product or technological solution, demonstrating the company's large global impact. Innovation remains one of the central pillars of the organization’s long term stra...

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

Position: • Data Analyst, Data Analytics (SQL, Python, GenAI) Company: • American Express Location: • Gurugram, Haryana, India Job Type: • Full Time Job Mode: • Hybrid Job Requisition ID: • 26009704 Years of Experience: • 0 to 2 Years Company Description • American Express is one of the world's most recognized financial services organizations, serving customers across numerous countries through a broad range of payment, lending, and financial solutions. • The company has built its reputation through a long history of innovation, customer trust, operational excellence, and a strong commitment to delivering exceptional service experiences. • American Express operates across consumer, commercial, and merchant services segments, helping businesses and individuals manage spending, improve financial efficiency, and access valuable rewards and benefits. • The organization emphasizes a culture where employees are encouraged to contribute ideas, challenge conventional approaches, and partic...

McCormick is hiring for an FRESHER entry level Data Scientist role in India

Position: Data Scientist Company: McCormick Location: Gurgaon, India Job type: Full Time Job mode: Onsite Job requisition id: Not specified Years of experience: 0-3 years Company Description • McCormick is a globally recognized food and flavor company with a long history dating back to 1889. • The organization was founded in Baltimore, Maryland, and has grown from a small business into one of the world's leading flavor companies. • The company develops, manufactures, markets, and distributes spices, seasoning blends, condiments, sauces, and flavor solutions. • McCormick serves a broad customer base that includes retailers, food manufacturers, restaurants, foodservice providers, and consumers. • The company operates in numerous countries and supports customers across a large number of international markets. • With thousands of employees worldwide, McCormick has established itself as a trusted name within the food industry. • Innovation, quality, and customer focus remain central to ...

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

Position: • Junior Data Analyst Company: • Hypersonix Location: • Remote Job type: • Full Time Job mode: • Remote Job requisition id: • Not specified Years of experience: • Entry Level • 0-3 years About the Position • Hypersonix is seeking a motivated and detail oriented Junior Data Analyst to join its growing team and contribute to the development of modern analytics solutions for clients. • This role offers an opportunity to work alongside implementation specialists, customers, data engineers, software engineers, product managers, and data scientists to transform business requirements into meaningful analytical outcomes. • The successful candidate will play an important role in helping organizations derive value from data by supporting the creation of data warehouses, dashboards, reporting frameworks, and machine learning driven insights. • Individuals who enjoy solving business problems using data, analytics, and visualization tools will find this role both challenging and rewar...

Vanderlande is hiring for an FRESHER entry level Data Modeler role in India

Position: • Data Modeler Company: • Vanderlande Location: • Pune, India Job type: • Full Time Job mode: • Onsite Job requisition id: • JR36872 Years of experience: • 0-3 years Company Description About Vanderlande • Vanderlande is recognized as one of the world's leading organizations in the field of logistics process automation and intelligent material handling solutions. • The company designs, develops, implements, and supports advanced technologies that help airports, parcel distribution centers, and warehouse operations improve efficiency, productivity, and operational performance. • Over the years, Vanderlande has established a strong global presence and serves some of the most recognized organizations across transportation, logistics, retail, and parcel delivery industries. • Its solutions are used by major international airports, large parcel handling organizations, and global retail enterprises that rely on efficient movement of goods and materials. • The company combines i...

slice is hiring for a Data Analyst

Position: Data Analyst Company: slice Location: Bengaluru, Karnataka, India Job type: Full-time Job mode: On-site Job requisition id: Not specified Years of experience: Entry level (1-3 years) Company Description: slice aims to simplify financial management and empower individuals with control over their money and time. The company prioritizes enhancing consumer experiences through innovative financial services. With a focus on accessibility, slice offers products like slice account, slice UPI, and slice borrow. slice is supported by prominent investors such as Tiger Global, Insight Partners, Advent International, Blume Ventures, and Gunosy Capital. Profile Overview: The average age of employees at slice is 26, fostering a culture of innovation, self-motivation, and happiness. Employees at slice are encouraged to embrace the present moment, fostering a harmonious and successful work environment. Qualifications: Demonstrated drive to create impactful solutions benefiting millions of cus...

Grexa AI is hiring for an FRESHER entry level Data Analyst Intern role in India

Position: • Data Analyst Intern Company: • Grexa AI Location: • Navi Mumbai, India Job type: • Full Time Job mode: • Onsite Job requisition id: • Not specified Years of experience: • 0 to 3 years Company Description About the Organization • Grexa AI is an emerging technology startup focused on transforming how small and medium businesses approach digital marketing through the power of artificial intelligence. • The company is working toward creating a next generation marketing platform capable of operating with minimal human intervention while helping businesses generate measurable revenue outcomes. • Unlike traditional marketing tools that require continuous manual effort, the organization aims to create intelligent systems that can automate decision making, campaign optimization, audience targeting, performance tracking, and marketing execution. • The business has been established by a group of experienced entrepreneurs and technology leaders who have previously built and scaled succ...

SettleMed is hiring for an entry level AI/ML Engineer role in India

Position: • AI/ML Engineer Company: • SettleMed Location: • Greater Noida, Uttar Pradesh, India Job Type: • Full Time Job Mode: • Remote Job Requisition ID: • Not Specified Years of Experience: • 1 to 3 Years Company Description • SettleMed is a healthcare technology organization focused on improving operational efficiency across the healthcare and medical claims ecosystem through the use of advanced digital technologies and artificial intelligence. • The company aims to simplify healthcare administration by creating technology driven solutions that reduce manual intervention, improve communication, and enhance transparency among various participants within the healthcare system. • SettleMed works toward addressing common challenges associated with healthcare claim management, documentation processing, stakeholder coordination, and operational workflows. • The organization is building intelligent digital systems that help healthcare providers, administrators, insurance stakeholders, an...