Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 6th, 2004, 04:57 AM
corrupted_wise corrupted_wise is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Kansas
Posts: 70 corrupted_wise User rank is Private First Class (20 - 50 Reputation Level)corrupted_wise User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 12 h 52 m 6 sec
Reputation Power: 6
SQL: Insert...Select?

Hi, i'm looking for a way to duplicate records in a table to the same table, but i need to change fields in the duplicated entries. Does this make sense?

Here's what i got
Code:
$t = mysql_query('SELECT from `table` where `country` = "us"') || die(mysql_error());

while($row = mysql_fetch_assoc($t)) {
extract($row);

$row["another_field"] = "this";
$row["another_field2"] = "that";

// need to it to auto intrement
unset($row["id"]);

mysql_query("INSERT into `table` ... $row ... blah blah") || die(mysql_error());
} // end while


That's works all fine and dandy, but it can sometimes lead to an unreasonable amount of queries. I read into Insert...Select but haven't tested it yet.

Code:
INSERT into `table` SELECT * FROM `table` where `country` = 'us'

Would this work?

Ok, say it did or whatever. Can i get a php function to give me a list of new rows so i could update them? Would mysql_affected_rows() do the job?

Thanks.


EDIT: n/m got the query to work and used select `table` desc limit affected_rows(), rows like a charm. Sometimes ya just gotta be patient

Last edited by corrupted_wise : January 6th, 2004 at 05:36 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > SQL: Insert...Select?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT