By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table company (
company_id int primary key,
name char(1)
);
insert into company values
(1,'a'),
(2,'b'),
(3,'c');
create table hotel_company (
hotel_id int,
company_id int,
primary key (hotel_id, company_id)
);
insert into hotel_company values
(1,1),
(2,1),
(3,5),
(4,6);
create table company_places (
id int primary key,
company_id int,
place_id int
);
insert into company_places values
(1,1,4),
(2,5,3),
(3,6,4),
(4,2,4);
select * from company_places;
select * from hotel_company;
Records: 3 Duplicates: 0 Warnings: 0
Records: 4 Duplicates: 0 Warnings: 0
Records: 4 Duplicates: 0 Warnings: 0
id | company_id | place_id |
---|---|---|
1 | 1 | 4 |
2 | 5 | 3 |
3 | 6 | 4 |
4 | 2 | 4 |
hotel_id | company_id |
---|---|
1 | 1 |
2 | 1 |
3 | 5 |
4 | 6 |
Rows matched: 4 Changed: 4 Warnings: 0
id | company_id | place_id |
---|---|---|
1 | 1 | 4 |
2 | 3 | 3 |
3 | 1 | 4 |
4 | 2 | 4 |
hotel_id | company_id |
---|---|
1 | 1 |
2 | 1 |
3 | 3 |
4 | 1 |