If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Duplicating rows in a column but changing one of the fileds

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-26-10, 07:40
kevinkhan kevinkhan is offline
Registered User
 
Join Date: Nov 2010
Posts: 4
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
Reply With Quote
  #2 (permalink)  
Old 11-26-10, 08:09
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-26-10, 09:49
kevinkhan kevinkhan is offline
Registered User
 
Join Date: Nov 2010
Posts: 4
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.
Reply With Quote
  #4 (permalink)  
Old 11-26-10, 10:04
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
INSERT
  INTO Classified
     ( user 
     , description 
     , link 
     , img1 
     , published )
SELECT 'email2@hotmail.com' 
     , description 
     , link 
     , img1 
     , published 
  FROM Classified
 WHERE user = 'email1@hotmail.com'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-26-10, 10:27
kevinkhan kevinkhan is offline
Registered User
 
Join Date: Nov 2010
Posts: 4
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On