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

DataVinci is hiring for a FRESHER entry level Junior Data Analyst role in India

Position: Junior Data Analyst Entry level opportunity designed for fresh graduates and individuals beginning their careers in analytics Role focused on supporting data operations, reporting, and business insights generation Opportunity to work closely with senior data professionals and learn practical, real world data workflows Involves handling raw datasets, transforming them, and contributing to decision making processes Designed for candidates who are curious, detail oriented, and willing to learn in a fast paced environment Company: DataVinci Private Limited A company focused on delivering digital analytics and data driven solutions Works with organizations primarily based in developed markets Provides services across data collection, transformation, analysis, and reporting Specializes in building scalable analytics systems for business decision making Known for leveraging modern analytics tools and platforms to deliver actionable insights Location: Work from home...

CoinDCX is hiring for a Data Analyst Intern role in India

Position: Intern, Data Analyst Entry level internship role focused on automation, reporting, and data analysis Opportunity designed for fresh graduates or early stage professionals looking to build strong foundations in data workflows Company: CoinDCX One of India’s leading cryptocurrency platforms working towards simplifying access to digital assets A fast growing fintech organization focused on blockchain innovation and financial transformation Location: Bangalore, India Primary work base aligned with company’s office setup Job type: Internship Full time engagement during internship period Job mode: Onsite Work from office environment encouraging collaboration and faster execution Job requisition id: 1597 Years of experience: 0 years  College students can also apply  Freshers and early learners are encouraged to apply Company description: CoinDCX is a pioneering organization in the crypto and blockchain space in India, focused on enabling indiv...

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

Position: Data Analyst, Analytics and Metrics Entry level role focused on supporting analytics driven decision making within a global services organization Involves working closely with project teams, stakeholders, and business units to improve operational efficiency Requires a balance of analytical thinking, stakeholder coordination, and process improvement mindset Company: Mastercard Location: Gurgaon, India Job type: Full time Job mode: Onsite Job requisition id: R 269625 Years of experience: 0 to 3 years Company description: Mastercard is a global technology company that plays a central role in enabling digital payments across more than 200 countries and territories The company focuses on building an inclusive and sustainable economy where individuals, businesses, and governments can participate and grow It provides secure, fast, and seamless payment solutions that make financial transactions simple and accessible for people worldwide Through strong part...

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

Position: Associate Data Analyst, Data Strategy-1 Entry level opportunity focused on data strategy, data quality, and analytics Designed for candidates who are beginning their careers in data and analytics Involves working closely with cross functional teams to ensure high quality data usage across business units Combines analytical thinking with technical execution across dashboards, pipelines, and reporting Offers exposure to enterprise scale data systems and real world business impact Company: Mastercard A globally recognized payments technology company operating in over 200 countries and territories Focused on enabling secure, seamless, and accessible digital transactions worldwide Known for building scalable financial infrastructure that powers individuals, businesses, and governments Strong emphasis on innovation, partnerships, and digital transformation A leader in driving financial inclusion and building sustainable economic ecosystems Location: Gurgaon, India ...

United Airlines is hiring for a FRESHER entry level Associate Data Analyst role in India

Position: Associate Data Analyst, Aeronautical Data Entry level role focused on aviation data handling, operational insights, and supporting flight dispatch functions Works closely with network operations, dispatch teams, and cross functional stakeholders to ensure smooth airline operations Acts as a central coordination point for aeronautical data validation, interpretation, and communication Plays a supporting role in ensuring global airline operations run safely and efficiently Company: United Airlines India Knowledge Center A subsidiary unit supporting global airline operations through analytics, engineering, and digital solutions Focused on enabling operational excellence, customer experience, and innovation in aviation systems Known for building scalable data driven solutions for global airline networks Location: Gurugram, Haryana, India Corporate office environment with exposure to global airline operations Works in coordination with teams across multiple intern...

Zorvyn FinTech Job Scam: Likely collecting your personal information

If you’ve been actively searching for internships or entry-level roles recently, especially in tech or data, there’s a good chance you’ve come across something called “Zorvyn FinTech.” Maybe it showed up on a job portal. Maybe you saw a reel claiming ₹40,000 stipend and a ₹14 LPA PPO. Or maybe someone forwarded it in a college WhatsApp group saying “apply fast.” At first glance, it looks like a dream opportunity. But here’s the thing. In today’s job market, when something looks too good to be true, it usually deserves a second look. Not panic. Not blind trust. Just a proper, calm verification. This article is not about calling any company a scam without proof. It is about helping you think clearly, spot patterns, and avoid getting misled in a market where freshers are already struggling. Why this matters more than ever Right now, the entry-level job market is extremely competitive. There are more applicants than openings. Companies are becoming selective. Many are cutting costs. Even w...

Kissht is hiring for a FRESHER entry level Data Analyst role in India

Position: Data Analyst Entry level opportunity designed for individuals beginning their professional journey in analytics Role focused on translating raw data into meaningful business insights Opportunity to work closely with multiple departments including product, credit, and operations Position emphasizes learning, growth, and practical exposure to real-world data challenges Ideal for candidates who are passionate about numbers, trends, and decision-making Exposure to modern analytics tools and business intelligence platforms Strong focus on building foundational skills in data handling and interpretation Company: Kissht A rapidly growing financial technology organization operating in the consumer lending space Recognized as a certified Great Place to Work organization Known for its technology-driven approach to credit and lending solutions Serves millions of users across India, including a significant presence in smaller cities Built on strong leadership with found...

United Airlines is hiring for a FRESHER entry level Associate Data Analyst role in India

Position: Associate Data Analyst Entry level role designed for individuals starting their journey in analytics Focused on supporting operational decision making using data Involves working closely with business teams, especially within air operations Requires a balance between technical skills and business understanding Opportunity to contribute to real world airline operations and impact outcomes Exposure to large scale enterprise data environments Involves both structured reporting and exploratory analysis Role demands curiosity, ownership, and continuous learning mindset Company: United Airlines Business Services Pvt. Ltd. A fully owned subsidiary of United Airlines Inc. Operates as a global support and operations hub for the parent organization Plays a key role in enabling analytics, technology, and operational efficiency Supports various business units including flight operations and inflight services Known for leveraging data to drive large scale operational de...

United Airlines is hiring for a FRESHER entry level Associate Data Scientist role in India

Position: Associate Data Scientist role focused on solving real world business challenges using analytics and operations research techniques Entry level opportunity designed for individuals looking to begin their journey in data science within a large scale enterprise environment Involves working closely with cross functional teams to build impactful solutions that influence decision making across business units Requires strong analytical thinking, problem solving mindset, and the ability to translate data into actionable insights Emphasis on leveraging mathematical models, optimization techniques, and machine learning approaches to drive efficiency and performance Company: United Airlines Business Services Pvt Ltd, a fully owned subsidiary of United Airlines Inc A global aviation leader known for connecting destinations across an extensive international network Focuses on building innovative digital solutions that enhance customer experience and operational efficiency Stro...

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

"The opening was closed just 15 minutes after it was posted." Position: Data Scientist, entry level role designed for individuals beginning their professional journey in the data science domain Opportunity to work on real world financial services problems using advanced analytics and machine learning Involves collaboration with multiple teams to solve business problems using data driven approaches Focus on building, testing, and improving scalable models and data driven solutions Role emphasizes both technical skills and business understanding Encourages ownership from day one, allowing individuals to take responsibility for projects and outcomes Exposure to large scale systems that handle millions of users and transactions daily Company: PhonePe Limited A leading digital payments and financial services company headquartered in India Known for its flagship digital payments application launched in August 2016 The platform has achieved massive adoption with hundre...