Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Transfer Copy Row to Another Table

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

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
votes: 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_query("INSERT INTO table2 (SELECT * FROM table1 WHERE name = '".$name."' LIMIT 1)");

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

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2002
votes: 8

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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members