[英]SQL More rows with the same ID but one different column
I am trying to replicate several rows where we have id_product, id category and position (irrelevant, it can just stay 0).我正在尝试复制我们有 id_product、id 类别和 position 的几行(无关紧要,它可以保持为 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.我希望这些行具有相同的 id_product 但具有不同的 id_category 但它一直告诉我我正在犯语法错误。
INSERT INTO `category_product` (col1, '143', 0)
SELECT col1 FROM category_product.id_product WHERE id_category = 12;
I am using MariaDB / PHPMyAdmin.我正在使用 MariaDB / PHPMyAdmin。
use insert select.使用插入 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.