homepage Welcome to WebmasterWorld Guest from 50.19.206.49
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Transfer Copy Row to Another Table
ocon




msg:4485309
 5:06 am on Aug 16, 2012 (gmt 0)

I have a database with many columns that I would like to copy whole rows from to insert into a second table.

The structures between the two tables are the exact same.

I'd like to avoid having to specify every column name and column value.

I've adapted this code from other forum posts, but I can't get it to work for me. Am I doing something wrong?

$mysql_connect = mysql_connect(...);
mysql_select_db(...);
mysql_set_charset(...);

mysql_query("INSERT INTO table2 (SELECT * FROM table1 WHERE name = '".$name."' LIMIT 1)");

mysql_close($mysql_connect);

 

topr8




msg:4485352
 7:21 am on Aug 16, 2012 (gmt 0)


maybe something like

INSERT INTO table2(*) SELECT * FROM table1 WHERE name = '".$name."' LIMIT 1

--- i've not done it.

Alternatively, if there are lots of column names why don't you get them in a query, somethign like:

SELECT column_name FROM information_schema.columns WHERE table_name = tablename

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved