I have 3 tables
1 table with all the information which I want to extract to two tables
[flat file]
name / team / town
[team table]
teamID/ team / town
[person table]
personID/ name / teamID
now I can use INSERT INTO SELECT to fill the values of the team table but i have hit a roadblock because I cant find a way to put the corresponding teamID in with the team that they are in.
I tried something like this but it just ends up repeating the name with each and every teamID
INSERT INTO person(name,teamID)
SELECT DISTINCT name,teamID FROM file,team
2
Answers
When you use Joins you will get the wanted results for your table
You can use the query below –
INSERT INTO person(name,teamID)
SELECT DISTINCT f.name,t.teamID
FROM file as f
JOIN team as t
ON f.teamID = t.teamID;