Forum Moderators: coopster
For example...
I want to move (productid, category, spec1, spec2, spec3, spec4) from TABLE1 to (productid, category, spec1, spec2, spec3, spec4) in TABLE2.
I appreicate any help that could help me on this.
i think birdmans proposal is best for this. after copying the table, just open the preferences of the new one and drop the fields/colums you do not need.
there is another solution by creating a (temporary) table, but you'll need the latest (?!) max version of mysql and you have to type the sql string in by yourself. so this is more compilicated. if you need the sql strings for such an operation, please post.
I actually want to move (productid, category, spec1, spec2, spec3, spec4) from TABLE1 to (productid, category, spec9(w), spec(x), spec(y), spec4(z) in TABLE2.
In other words, the columns I'm going to move are different each time.
When I select a cateogry (9), (spec1, spec2, spec3, spec4) will be moved to (spec11, spec12, spec13, spec14). Therefore, I would like to know how to do this via mySQL statements.
Thanks again for your help!
For category 9,
category - 9
spec1 -> spec1
spec2 -> spec2
spec3 -> spec3
spec4 -> spec4
For category 10,
category - 10
spec5 -> spec1
spec6 -> spec2
spec7 -> spec3
spec8 -> spec4
I want to do something similar to this.
I only need a few general commands that can do this.
now i got the point. if you're familiar with sql (in general), then the hint is the
sql command. this is for mysql i think you're using it and the command is described in detail with usercomments in the mysql docs [mysql.com]. INSERT .... SELECT
in short it's a combination of an insert and a select command giving you all the possiblities you need: With
statement you can quickly insert many rows into a table from one or many tables. INSERT ... SELECT
did this help?
There is nothing that prevents you from running such a query by using PHP [php.net]īs mysql_query() [php.net].
Andreas
You will need to store your selected data temporarily in a mysql_fetch_array() [php.net] then run a while loop and INSERT [mysql.com] them INTO your new table.
$sql = "SELECT [mysql.com] productid, category, spec1, spec2, spec3, spec4 FROM table1";
$result = mysql_query [php.net]($sql);
while($i = mysql_fetch_array [php.net]($result)){
$sql = "INSERT [mysql.com] INTO table2 VALUES($1[productid],'$i[category]','$i[spec1],$i[spec2],'$i[spec3]','$i[spec4]');
mysql_query [php.net]($sql);
}
Something like that ;)
since you didn't answer i don't know if my last suggestion worked out for your or you understood it.
i know that you want to put it into the phpmyadmin sql query field, this is the code which should work. i haven't tested it myself because i don't have this kind of db structure but since you posted some details, it might do a good job:
INSERT INTO table2 (spec1,spec2,spec3,spec4) SELECT
spec1 AS spec1, spec2 AS spec2, spec3 AS spec3, spec4 AS spec4
FROM table1 WHERE category=9;
INSERT INTO table2 (spec1,spec2,spec3,spec4) SELECT
spec5 AS spec1, spec6 AS spec2, spec7 AS spec3, spec8 AS spec4
FROM table1 WHERE category=10;