【发布时间】:2015-03-01 08:34:39
【问题描述】:
我尝试使用以下 sql 语法更新一些记录
update product_class1 t1
join product_class1 t2
on t1.family_code = t2.family_code
set t1.parent_id = t2.id
where t1.id < 145
and t1.id > 140
and t2.class_code = ''
它给了我零 (0) 记录结果
虽然我尝试使用类似的 sql 语法执行 select 语句
select *
from product_class2 t1
join product_class2 t2
on t1.family_code = t2.family_code
where t1.id < 145
and t1.id > 140
and t2.class_code = ''
它给了我 4 条记录结果。
我不知道我的 update sql 语句有什么问题。 不胜感激,如果有人能指出这个建议。
问候
【问题讨论】:
-
我不确定是否是这种情况,但请注意,在您的更新查询中,您将
product_class1与自身连接,在选择查询product_class2中也与自身连接。您能否验证并最终更新问题? (简而言之,您尝试根据product_class1更新并仅从product_class2中选择) -
对于更新,您在 product_class1 上进行自我加入,在选择中,您在 product_class2 上进行自我加入。在您引用不同表的两个查询中。
-
是的,对不起我的错误