Page 1 of 1

INSERT INTO... SELECT.... FROM

Posted: Fri Feb 11, 2005 3:25 pm
by neophyte
I'm working on copying some data from one db to another. The sql I've written (INSERT INTO SELECT FROM) works but on record 19 it says

'' duplicate entry for key 2.

The next record is 20 not '' in the table I'm copying from. I'm confused on why this is happening and how do I fix it or work around it.

Any ideas?

Thanks 0 plenty!

Posted: Fri Feb 11, 2005 3:26 pm
by feyd
want to post the query?

Sure

Posted: Fri Feb 11, 2005 3:31 pm
by neophyte
I'll post it....

Code: Select all

INSERT INTO mad_users ( username, pwd, firstname, lastname, email) SELECT  ddl_user.username, ddl_user.password, ddl_user.firstname, ddl_user.lastname, ddl_user.email  FROM ddl.ddll_user

Posted: Fri Feb 11, 2005 3:33 pm
by feyd
which fields in the insert are unique/primary keys? is this same field a unique/primary key in the selection table?

Posted: Fri Feb 11, 2005 3:55 pm
by neophyte
There is only one key in each table. In both cases it's the 'id' field. I dropped them from the query because in both cases the are also auto_incrementing. The table I'm copying from has about 40 records and I checked the numbers to make sure they are sequential and that they are all there. It checked out.