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

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

Position: Analyst - Data Company: Huron Location: Bangalore, India Job type: Full time Job mode: Hybrid Job requisition id: JR-0016515 Years of experience: 0 to 3 Years Company description Huron operates as a premier global consultancy firm that is deeply dedicated to forming robust, strategic collaborations with a wide array of clients to facilitate sustainable and continuous growth across diverse operational verticals. The organization places a paramount emphasis on igniting innovation from within, equipping client enterprises with the necessary tools, frameworks, and mindsets to successfully navigate the complexities of constant, unpredictable market changes. By seamlessly blending high-level strategic planning with deep domain expertise and innovative creativity, the firm acts as a catalyst for comprehensive organizational evolution and market adaptation. The company is strictly focused on accelerating transformation across three primary pillars: operational efficiency, digital mod...

SCG is hiring for an FRESHER entry level Data Analyst/Engineer role in India

Position: Data Analyst/Engineer  Company: SCG  Location: New Delhi, Delhi, India  Job type: Full-time  Job mode: On-site  Job requisition id: Not Specified in the original JD Years of experience: 0-3 years Company description SCG stands as a monumental and premier business conglomerate within the Southeast Asian region, consistently demonstrating regional focus and established commitments toward highly ethical business conduct. The organization was fundamentally established in the year 1913 and has since experienced exponential growth, transforming into a highly diversified group of industrial operations. SCG encompasses three major and core business units that drive its immense revenue and market presence: SCG Cement-Building Materials, SCG Chemicals, and SCG Packaging. The enterprise is deeply rooted in operations that are strictly in line with robust corporate governance and universally accepted sustainable development principles. Demonstrating a profound com...

Praxair India (Linde) is hiring for an FRESHER entry level Data Scientist role in India

Position Data Scientist Company Praxair India Private Limited (Linde) Location Bangalore, Karnataka, India Job type Regular / Permanent / Unlimited / Full-Time Job mode On-Site Job requisition id req33180 Years of experience 0 - 3 Years (Fresher / Entry Level) Company description Linde plc represents a premier global entity in the industrial gases and specialized engineering sector, establishing an authoritative operational presence across more than one hundred countries worldwide. The organization maintains a steadfast mission dedicated to making the world significantly more productive on a daily basis through the continuous creation and implementation of superior technological solutions, products, and operational services. Through cutting-edge process design, industrial automation, and technological innovation, the enterprise enhances customer operational success while simultaneously prioritizing environmental preservation and planetary sustainability. Praxair India Private Limited o...

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

Position: Data Analyst Company: EnKash Location: Pune City, Maharashtra, India Job type: Full-time employment opportunity Job mode: On-site work model Job requisition id: Not explicitly specified / Internal tracking reference Years of experience: 0 to 1 year of professional experience, welcoming talented freshers with robust academic backgrounds, internships, or practical analytical projects Company description EnKash operates as a premier B2B fintech enterprise that is fundamentally transforming the landscape of corporate spend management and digital business payments. The organization delivers an all-encompassing, unified software platform specifically designed to handle corporate payables, receivables, business credit cards, and comprehensive expense workflows. Supported by critical regulatory licenses issued by the Reserve Bank of India, including Payment Aggregator, Prepaid Payment Instrument Issuer, and Bharat Bill Payment Operating Unit authorizations, EnKash empowers commercial...

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

Position: Analyst-Data Analytics (Data Analyst) Company: American Express Location: Gurugram, Haryana, India Job type: Full-time Job mode: Hybrid Job requisition id: 26014019 Years of experience: 0 to 3 Years (Entry Level) Company description American Express stands as a globally integrated payments company, providing customers with unmatched access to products, insights, and experiences that enrich lives and build business success on a worldwide scale. Tracing its roots back 175 years, the organization was founded on a bedrock of trust, security, and an unwavering commitment to unparalleled customer service, evolving from an express mail business into a modern powerhouse of financial technology and global commerce. The company operates with a deeply ingrained culture that prioritizes shared values and specific leadership behaviors designed to foster collaboration, drive continuous innovation, and maintain the highest ethical standards across all lines of business. At its core, the bra...

Bain & Company is hiring for an FRESHER entry level Analyst - Data & Insights role in India

Position: Analyst - Data & Insights (CP) Company: Bain & Company (Bain Capability Network) Location: Gurgaon / New Delhi, India Job type: Permanent Full-Time Job mode: Hybrid / Onsite Job requisition id: 109944 Years of experience: 0 - 18 Months (0 to 1.5 Years) Company description Bain & Company stands as one of the world's most prestigious, globally renowned, and influential strategic management consulting firms, dedicated to empowering top-tier corporate leaders, executive boards, innovative business founders, and non-profit change-makers across every major industry sector worldwide. Established in 1973 with a transformative philosophy centered on real-world business outcomes, Bain & Company has grown its global network to encompass over 61 strategically positioned office locations spanning across 39 distinct nations across North America, Europe, Asia-Pacific, Latin America, and the Middle East. The core operating model of Bain & Company emphasizes working al...

Houlihan Lokey is hiring for an FRESHER entry level Data Analytics / Data Science Intern role in India

Position: Data Analytics / Data Science Intern Company: Houlihan Lokey, Inc. Location: Gurugram, Haryana, India Job Type: Full-time Job Mode: On-site Job Requisition ID: R3540 Years of Experience: 0 to 1 Year (Final year students can also apply) Company Description Global Corporate Identity and Market Positioning Houlihan Lokey operates as a preeminent global investment banking powerhouse, distinguished by its unwavering commitment to providing independent, objective strategic and financial advice. The firm caters to a diverse, high-profile clientele comprising major corporations, private equity firms, institutional investors, and sovereign governments navigating complex financial environments. Through a partnership-driven business model grounded in mutual trust and deep-seated industry expertise, Houlihan Lokey crafts innovative, integrated financial solutions across multiple disciplines. Core advisory verticals encompass mergers and acquisitions (M&A), capital markets raising, co...

Mastercard is hiring for an entry level Data Scientist role in India

Position Data Scientist (Data Visualisation) Company Mastercard Location Gurgaon, India Job type Full-time Job mode Hybrid Job requisition id R-288306 Years of experience 1–3 years (internship and personal project experience can be counted) Company description Mastercard operates as a global technology engine within the international payments and financial services industry, facilitating electronic commerce and digital payment transactions across more than two hundred countries and territories worldwide. The organization serves as an interconnected framework powering modern global economies, enabling individual consumers, commercial enterprises, financial institutions, and government entities to execute transactions securely, seamlessly, and efficiently. Mastercard’s foundational purpose centers on building an inclusive, sustainable, and technologically accessible digital economy where every participant can realize their potential and achieve sustainable prosperity. By providing an ext...

NTT DATA is hiring for an FRESHER entry level Power BI Developer role in India

Position Power BI Developer specialized in building robust analytics solutions, interactive executive dashboards, and scalable business intelligence frameworks. Responsible for transforming complex, raw enterprise datasets into intuitive, visually compelling, and actionable visual reports. Core focus on dashboard design excellence, user experience optimization, and aligning visual data presentation with strategic business objectives. Driving semantic model creation, data shaping, relational modeling, and performance tuning to support seamless user interactions. Engaging directly with cross-functional business stakeholders to gather requirements, iterate on report designs, and validate analytical findings. Executing rigorous quality assurance testing, troubleshooting performance bottlenecks, and maintaining high standards of data accuracy. Documenting technical architectures, report logic, and user enablement guides to ensure smooth onboarding and long-term maintainability. Company NTT ...

Xiarch Bharat Pvt Ltd is hiring for an FRESHER entry level Agentic AI Engineer Intern role in India

Position Agentic AI Engineer Intern Autonomous Systems & Workflow Automation Developer Generative AI and LLM Integration Engineer Company Xiarch Bharat Pvt Ltd CERT-In Empanelled Cybersecurity & Enterprise Solutions Provider Advanced AI-Powered Security Operations Leader Location Haryana, India Postal Code: 122018 Regional Hub Serving Pan-India Enterprise Operations Job type Full-time Internship Program Immersive Technical Development Role Job mode Onsite Engineering Deployment Collaborative Team Environment Job requisition id Internal Tracking Identifier: XB-AI-2026-09 Years of experience 0 to 3 Years of Technical Experience Freshers and Self-Driven Explorers Welcome Company description Xiarch Bharat is a highly respected, CERT-In empanelled cybersecurity services firm boasting over two decades of robust industry experience and technological leadership. The organization specializes in delivering comprehensive, round-the-clock Security Operations Center (SOC) monitoring, advanc...