简体   繁体   English

SQL 更多行 ID 相同但列不同

[英]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.

相关问题 SQL 合并两行ID相同但列值不同的行 - SQL Merge two rows with same ID but different column values 根据不同列的行之一上的值返回具有相同 id 的所有行 - Return all rows that have the same id based on a value on one of the rows of a different column Select 行,其中 ID 相同但名称在多个记录中包含不同数据 - Select rows where ID is same but Name contains different data in more than one record SQL,一个在一列中具有不同值的id - SQL, One id with different values in one column SQL:如何根据一个 ID 存在 2 个不同列的值来过滤 SQL 中的行? - SQL: How to filter rows in SQL based on existence of a 2 different column's value against one ID? 如何创建一个表,其中一列包含具有不同ID的所有行的相同值?(有关说明,请参见布局) - How to create a table where one column contains a same value for all rows with different id?(See Layout for clarity) 在 mysql 中在一列中合并多行? 当具有不同值的相同 ID 时 - In mysql combine multiple rows in one column? when having same ID with different value 将具有相同id但不同列值的两行合并为一行[mysql] - merge two rows with same id but different column values into one row [mysql] SQL在具有相同ID和不同第二个ID的表行中添加 - SQL adding in table rows with same id and different second id SQL查询在一个查询中求和同一ID列的两个不同值 - SQL query to sum two different values of same ID column in one query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM