[英]Insert Query is inserting only first row from the result set in the database table
[英]Sqlite database insert data from other table is inserting one row only
从产品表插入包含quoted_id = 1的3行的数据时,我遇到问题。我只能从产品到价格表中获取第一个数据。
插入价格的代码
db.execsql("insert into price (name, quantity ) values ((select from product title, quantity where quote_id =1 ) ) " )
更新 :
我想在同一条语句中插入一个静态ID; 值= 1;
insert into price (price_id,name, quantity,row_total)
"+value+",select title, quantity,SUM(price*quantity)
from product where quote_id = 1
我想达到这个目的
您使用的语法不正确。 尝试这个:
insert into price (price_id, name, quantity)
select 1, title, quantity
from product
where quote_id = 1
在这种情况下,您不能使用关键字values
。
这将返回product
表where quote_id = 1
所有行where quote_id = 1
并将它们插入price
表。
如果仅返回1行,则将插入这1行。
price
表中是否还有其他约束不允许插入更多行,例如唯一索引?
编辑 :
db.execsql(
"insert into price (price_id, name, quantity) select " +
value +
", title, quantity from product where quote_id = 1");
如果“ quote_id”是价格表的主键,而产品表中的“ quote_id”是相同的,那么您就是在覆盖相同的记录。
如果不是这种情况,那么我建议查询产品,以确保存在quote_id = 1的多个记录。
db.execsql(“插入价格(名称,数量)选择标题,从quote_id = 1的产品中选择数量”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.