Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2010
    Posts
    7

    Unanswered: Duplicating rows in a column but changing one of the fileds

    Any ideas how i can do this?

    The structure of my database is

    CREATE TABLE IF NOT EXISTS `Classified` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `user` varchar(255) COLLATE latin1_general_ci NOT NULL,
    `description` text COLLATE latin1_general_ci NOT NULL,
    `link` varchar(128) COLLATE latin1_general_ci NOT NULL,
    `img1` varchar(128) COLLATE latin1_general_ci NOT NULL,
    `published` tinyint(1) NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1642 ;

    and all i wanna do is duplicate all rows (except auto increment id) that have a certain email we say email1@hotmail.com and insert them back into the same table but changing the email to email2@hotmail.com

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by kevinkhan View Post
    all i wanna do is duplicate all rows (except auto increment id) that have a certain email ...
    that's gonna be real difficult, because your table doesn't have an email column
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2010
    Posts
    7
    Quote Originally Posted by r937 View Post
    that's gonna be real difficult, because your table doesn't have an email column
    sorry i wasnt clear in my discription. the email field is actually the user field.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    INSERT
      INTO Classified
         ( user 
         , description 
         , link 
         , img1 
         , published )
    SELECT 'email2@hotmail.com' 
         , description 
         , link 
         , img1 
         , published 
      FROM Classified
     WHERE user = 'email1@hotmail.com'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Nov 2010
    Posts
    7

    Thumbs up

    Quote Originally Posted by r937 View Post
    Code:
    INSERT
      INTO Classified
         ( user 
         , description 
         , link 
         , img1 
         , published )
    SELECT 'email2@hotmail.com' 
         , description 
         , link 
         , img1 
         , published 
      FROM Classified
     WHERE user = 'email1@hotmail.com'
    Thanks that workded perfectly

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •