Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Each customer's first order

    Each customer's first order

    Mediumsqljoingroup byaggregate

    For each customer with at least one order, return customer (their name), first_order (the earliest ordered_on) and orders (their order count). Sort by name.

    Tables

    • customers (id INTEGER, name TEXT)
    • orders (id INTEGER, customer_id INTEGER, ordered_on TEXT)

    Example 1

    customers

    idname
    1Mona
    2Omar
    3Laila

    orders

    idcustomer_idordered_on
    112026-03-01
    222026-01-15
    312026-02-10

    Expected result

    customerfirst_orderorders
    Mona2026-02-102
    Omar2026-01-151

    Constraints

    • 0 ≤ rows ≤ 1000
    • Customer names are unique
    • The order of rows matters

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

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