【发布时间】:2017-05-17 22:27:05
【问题描述】:
我正在尝试更新名为 product_category_parent 的表的字段(例如 parent_id)。
这是我尝试使用的查询:
update sub_category_child set name='Mobile Phones', parent_id = (select parent_id from product_category_parent where cname = 'Appliances')
但它返回以下错误
#1064 - 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的“)”附近使用正确的语法
这是数据库架构
table product_category_parent
id cname
----- ----------
1 Electronics
table sub_category_child
id name parent_id
----- -------- -------------
1 Mobile Phone 1
parent_id 作为 product_category_parent.id 的外键
【问题讨论】:
-
请
describe相关表格。 -
好的,让我编辑问题
-
select parent_id from product_category_parent where cname = 'Appliances'是否产生超过 1 条记录?第二。您希望 Sub_category_Child 中的所有记录的名称为“Mobile Phones”,其 parent_ID 等于 product_Category_parent 中的父 ID,其中 cname = 'Appliances'? -
是的,它确实产生了超过 1 条记录
-
哎呀我的错我只想让一行受影响,这会改变产品ID