简体   繁体   English

错误 - 我在这个SQL查询中做错了什么?

[英]Error -What am i doing wrong in this sql query?

I am trying to update values in a table from the same table using a particular condition but it is not running 我试图使用特定条件从同一个表更新表中的值但它没有运行

I have tried it using "WITH" 我用“WITH”试了一下

update my_table as res1
set res1.my_column = (select res2.my_column from my_table as res2
                      where res2.parent_id is null and res2.is_company = true)
where res1.parent_id=res2.id;

只需尝试下面的SQL:

update my_table as res1 set my_column = res2.my_column from my_table res2 where res1.parent_id = res2.id and res2.partner_id is null and res2.is_company;

You don't specify the type of SQL server, but generally an UPDATE from a SELECT takes a particular syntax: 您没有指定SQL服务器的类型,但通常来自SELECT的UPDATE采用特定语法:

How do I UPDATE from a SELECT in SQL Server? 如何从SQL Server中的SELECT更新?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM