Juan Velez
Juan Velez

Reputation: 741

MySQL insert into table not inserting all fields

I have 2 existing tables in a MySql DB. The tables have identical structures. I want to copy data from table to another.

insert into `Table1`
select * from Table2
where department = "engineering"

the above code seemed to work and it copied the data correctly except for 1 column. The "department" column did not copy over so it was blank. All the other fields seemed to copy over correctly for all of the records.

What can be causing this? As I mentioned both tables have identical structures, same number of columns and everything...

Any ideas?

Note:I just realized that there are actually 2 columns that are not copying over. The "department" and "Category" fields come over blank. So basically when I am inserting the data from table 2 into table 1, 12 out of 14 columns are successfully copied over but then there are 2 columns that remain blank.

Below is the DESCRIBE of Table1 and Table2

enter image description here

The only difference I can see when I do a Describe on both tables is that the 2 fields in question have a data type of enum (.....) but they have differences in between the parenthesis. Could this be causing the issue and if so is there a simple way around it? I'm thinking I might have to do an update query after I do the initial insert that will bring in the "department" and "category" fields from table 2 into table 1 by joining in the ID field.

Upvotes: 0

Views: 1735

Answers (1)

Hackerman
Hackerman

Reputation: 12295

From the docs:

If you insert an invalid value into an ENUM (that is, a string not present in the list of permitted values), the empty string is inserted instead as a special error value.

Read about ENUM.

Upvotes: 3

Related Questions