user17932693
user17932693

Reputation: 11

Duplicate entry error code in MySQL workbench

My lecturer has given me a document with raw data in and I have to create tables and implement it into MySQL.

Background: The raw data has multiple transactions from companies. Some transactions are from the same company so the same COMPANYID comes up often.

The lecturer told us to insert the raw data into a table titled RAW to store everything. Then we have to insert data into our smaller tables from that RAW table.

ISSUE: My issue is when I’m trying to create my table COMPANY, I obviously want to include the COMPANYID.

But when I use the code

Insert into COMPANY
Select distinct COMPANYID, COMPANYNAME, NumberofDivisions
From RAW;

I get the duplicate error because obviously in the RAW table, the same COMPANYID comes up multiple times for each transaction!

How can I only have the COMPANYID once in the COMPANY table?

Upvotes: 1

Views: 653

Answers (1)

SelvaRaj B
SelvaRaj B

Reputation: 96

Try insert ignore instead of insert which would continue inserting records till the end of file even though duplicate record error.

Insert ignore into COMPANY
Select distinct COMPANYID, COMPANYNAME, NumberofDivisions
From RAW;

Upvotes: 0

Related Questions