Reputation: 29
I am trying to replicate several rows where we have id_product, id category and position (irrelevant, it can just stay 0). I want these rows to have identical id_product but with a different id_category but it keeps telling me I am making a syntax error.
INSERT INTO `category_product` (col1, '143', 0)
SELECT col1 FROM category_product.id_product WHERE id_category = 12;
I am using MariaDB / PHPMyAdmin.
Upvotes: 0
Views: 22
Reputation: 133360
use insert select. selecting also the constant values
INSERT INTO `category_product` (col1, id_product, position)
SELECT col1 , '143',0
FROM category_product
where category_product.id_product WHERE id_category = 12;
Upvotes: 1