I’ve got a database which I need to alter.
The original database consists of 3 tables.
It now needs to be extended with one more table.
The data for the new table come from two tables of the original database.
I can create the table but I can’t populate it with the data.
The original tables are:
create table Accommodatie
(plaatscode varchar(3) not null,
accommodatienr numeric(3) not null,
accommodatiename varchar(25) not null,
adres varchar(25) not null,
plaatsnaam varchar(20) not null,
land varchar(20) not null,
email varchar(30) null,
internet varchar(30) null,
contactpersoon varchar(25) null,
primary key (plaatscode, accommodatienr));
create table Vervoer
(vervoercode numeric(5) not null,
plaatscode varchar(3) not null,
stedenadviseur varchar(20) not null,
vervoersoort varchar(12) not null,
maatschappij varchar(15) not null,
omschrijving varchar(50) not null,
overstap varchar(30) null,
primary key (vervoercode));
create table Vervoerprijs
(vervoercode numeric(5) not null,
seizoen varchar(6) not null,
prijs numeric(6,2) not null,
plaatscode varchar(3) not null,
primary key (vervoercode, seizoen),
foreign key (vervoercode) references Vervoer(vervoercode));
The new table looks like this:
CREATE TABLE Plaatscode
( plaatscode varchar(3) not null,
stedenadviseur varchar(20) not null,
land varchar(20) not null,
PRIMARY KEY (plaatscode));
For the new table I need plaatscode and land from Accommodatie and vervoerscode from the table vervoer.
Can you help me to build a query to populate the new table?
If all you want to do is populate your new table, the following should work: