Sobes.tech
Intern — Senior

Names of cities and their inhabitants

livecode

Task condition

Get a list of city names along with the names of users living in each of them.

-- Table "cities"
create table cities (
    id    serial primary key,
    name  text not null
);

insert into cities (name)
values
    ('Moscow'),
    ('Saint Petersburg'),
    ('Krasnodar');

-- Table "users"
create table users (
    id      serial primary key,
    name    text not null,
    city_id int not null references cities(id)
);

insert into users (name, city_id)
values
    ('Ivan', 1),
    ('Anna', 1),
    ('Oleg', 2);