Bob
Bob

Reputation: 107

Move data from import table

I have problem with my project. I'm scraping data about auctions with cars from websites and move it to my table 'Offers_in'. Next I want move it to smaller tables. Problem is how do this? Procedure, select as insert? Generally I want call procedure and data will be moved from offers_in to tables makes, models, versions ,fuel and auctions and delete from offers_in. Only I can do is insert makes to Table Makes. Id in Table Makes is AUTO_INCREMENT and Name field is UNIQUE. I do this with SQL:

INSERT IGNORE INTO makes(id_make, name)
    SELECT '0',o.make
    FROM offers_in o

Now ,how move data about models and how attribute model id_make?

Here is a my database schema

Database Schema

Thank you for any help.

Upvotes: 1

Views: 71

Answers (1)

Matt Goodis
Matt Goodis

Reputation: 393

just add a JOIN into your select;

INSERT INTO models(Name, id_makes)
SELECT offers_in.model, Makes.id
FROM offers_in INNER JOIN Makes ON Makes.name = offers_in.make

Upvotes: 1

Related Questions