Sobes.tech
Intern — Middle

Selection of cities with user presence

livecode

Task condition

Create an SQL query that outputs the city name and user name, excluding cities with no users.

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

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

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),
('Olesya', 2);

-- here should be a SELECT query