New database interview question named "States and Zip Codes"


  • 0

    Hello,

    I'd like to suggest new database interview question named States and Zip Codes. Details may be found below.

    mysql> select * from States;
    +----+-------------+
    | id | name        |
    +----+-------------+
    |  1 | Los Angeles |
    |  2 | Chicago     |
    +----+-------------+
    2 rows in set (0.00 sec)
    
    mysql> select * from Zip_codes;
    +----+-------+
    | id | value |
    +----+-------+
    |  1 | 63006 |
    |  2 | 63010 |
    |  3 | 60612 |
    +----+-------+
    3 rows in set (0.00 sec)
    
    mysql> select * from State_zip_codes;
    +------+----------+-------------+
    | id   | state_id | zip_code_id |
    +------+----------+-------------+
    |    1 |        1 |           1 |
    |    1 |        1 |           2 |
    |    3 |        2 |           3 |
    +------+----------+-------------+
    3 rows in set (0.00 sec)
    
    mysql> 
    select States.name, Zip_codes.value from States 
    join State_zip_codes on States.id = State_zip_codes.state_id 
    join Zip_codes on Zip_codes.id = State_zip_codes.zip_code_id;
    
    +-------------+-------+
    | name        | value |
    +-------------+-------+
    | Los Angeles | 63006 |
    | Los Angeles | 63010 |
    | Chicago     | 60612 |
    +-------------+-------+
    3 rows in set (0.00 sec)
    

    Regards,
    Olena


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.