Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Top earners per department

    Top earners per department

    Mediumsqljoinwindow functionssubquery

    For each department, return department (its name), employee and salary for the employee or employees earning that department's highest salary. Order doesn't matter.

    Tables

    • departments (id INTEGER, name TEXT)
    • employees (id INTEGER, name TEXT, salary INTEGER, department_id INTEGER)

    Example 1

    departments

    idname
    1Engineering
    2Sales

    employees

    idnamesalarydepartment_id
    1Mona300001
    2Omar250001
    3Laila200002
    4Ziad300001

    Expected result

    departmentemployeesalary
    EngineeringMona30000
    EngineeringZiad30000
    SalesLaila20000

    Constraints

    • 0 ≤ rows ≤ 1000
    • Any row order is accepted

    Submit checks your solution against 9 tests, including hidden ones.

    SQL
    -- Write one SELECT query. Tables: departments, employees
    SELECT
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.