Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Second highest salary

    Second highest salary

    Mediumsqlsubquerylimit offsetnull

    Return one row with a column second_highest: the second highest distinct salary in employees. If there isn't one (say, only one distinct salary), return NULL.

    Tables

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

    Example 1

    employees

    idnamesalarydepartment_id
    1Mona300001
    2Omar200001
    3Laila300002

    Expected result

    second_highest
    20000

    Example 2

    employees

    idnamesalarydepartment_id
    1Mona300001

    Expected result

    second_highest
    NULL

    Only one salary, so the result is NULL.

    Constraints

    • 0 ≤ rows ≤ 1000

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

    SQL
    -- Write one SELECT query. Tables: 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.