razz razz - 2 months ago 15
MySQL Question

Adding multiple rows mysql in phpmyadmin

I'm trying to execute a rather complicated task in phpmyadmin.
Shortly i need to add multiple rows in a table that uses a certain value from another table column.
I kinda figured out how to add 1 row manually) but since i need 11.000 of it..

INSERT INTO `DATABASE`.`ratings` (
`id` ,
`total_votes` ,
`total_value` ,
`used_ips`
)
VALUES (
'5000', '10', '1000', NULL
);


There are 2 TABLES (CONTENT and RATINGS) in same DB.
In CONTENT there is a column named CONTENT_RECORD (11.000 entries) which excists of only numbers

In RATINGS we have 4 colums (ID,TOTAL_VOTES,TOTAL_VALUE,USED_IPS)
I want to add multiple rows in RATING with following values.

ID = should copy the value from table CONTENT, column CONTENT_RECORD

Total_votes = fixed number 10

Total_value = fixed number 1000

used_ips = leave empty


Help would be much appreciated.

Answer

You can use insert..into..select syntax. Something like this -

INSERT INTO `DATABASE`.`ratings`(`id`, `total_votes`, `total_value`, `used_ips`)
SELECT CONTENT_RECORD, '10', '1000', NULL FROM CONTENT
Comments