INSERT INTO othertbl SELECT * tbl

Posted by Harry on Stack Overflow See other posts from Stack Overflow or by Harry
Published on 2010-05-07T16:15:43Z Indexed on 2010/05/07 16:18 UTC
Read the original article Hit count: 130

Filed under:

Current situation:

  INSERT INTO othertbl
    SELECT *
    FROM tbl       
  WHERE id = '1'

So i want to copy a record from tbl to othertbl. Both tables have an autoincremented unique index. Now the new record should have a new index, rather then the value of the index of the originating record else copying results in a index not unique error.

A solution would be to not use the * but since these tables have quite some columns i really think it's getting ugly.

So,.. is there a better way to copy a record which results in a new record in othertbl which has a new autoincremented index without having to write out all columns in the query and using a NULL value for the index.

-hope it makes sense....-

© Stack Overflow or respective owner

Related posts about mysql