Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving records from 1 table to another 1

Status
Not open for further replies.

ArtWerk

Programmer
Jul 31, 2006
66
US
Is there and easy SQL syntax to move or copy rows from 1 table to another?

I'm creating a temporary table and after matching duplicates, and deleting the duplicate rows, i want to move or copy the remaining rows into the permanent table.
 
ok, i'm having trouble with this just a bit.

I have existing data in a table called "pcp".

The columns will be outputted into a variable: $newcols (using PHP)

The columns i want to move the data from is in a table called: "temp"

Those columns are found with the variable: $newheaders

The SQL statement i'm using is:

Code:
INSERT INTO `".$list."` (".$newcols.") VALUES (SELECT ".$newheaders." FROM `temp`);

which results into something like:

Code:
INSERT INTO `pcp` (prov_id, phone, address2, city, state, county, primary_addr, max_panel, region, capacity, spec_id, spec_desc, languages) VALUES (SELECT prov_id, phone, address2, city, state, county, primary_addr, max_panel, region, capacity, spec_id, spec_desc, languages FROM `temp`);

Not exactly sure what i'm doing wrong, but it's not working right... I get an error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT prov_id, phone, address2, city, state, county, primary_addr, max_panel, r' at line 1
 
The syntax I provided should work. Instead of the *, you can list field names. Example:
[tt]
INSERT pcp
SELECT prov_id,phone,address2, ...
FROM temp
[/tt]
 
Sorry, I meant:
[tt]
INSERT pcp (prov_id,phone,address2, ...)
SELECT prov_id,phone,address2, ...
FROM temp
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top