List:General Discussion« Previous MessageNext Message »
From:Jigal van Hemert Date:April 19 2005 11:11am
Subject:Re: Duplication of records within the same table.
View as plain text  
From: "Lee Denny"
> site_id, page_id,header_text,main_text..
>
> I just need to duplicate existing records with a new site_id, so :
>
> 1,1,Hello,some text..
> 1,2,Hello Again, some more text...
>
> gets copied to
>
> 2,3,Hello,some text..
> 2,4,Hello Again, some more text...
>
> page_id is already auto_increment.
>
> I'm sure that an INSERT .. SELECT statement should do it, but I'm unsure
of
> the correct syntax.
>

INSERT INTO `<tablename>` SELECT <new_site_id>, NULL, `header_text`,
`main_text` FROM `<tablename>` WHERE `site_id`=<old_site_id>

NULL will let MySQL use the autoincrement...
Tested on 4.0.23-standard

Regards, Jigal.

Thread
Duplication of records within the same table.Lee Denny19 Apr
  • Re: Duplication of records within the same table.Jigal van Hemert19 Apr