[英]Update query that will set specific columns in a record with values from another record of same table
look at this query; 查看此查询;
update user_data set old_status= 'SNNNNS',
user_group='15',
default_rate='DEFAULT',
entity_num='1001'
where user_name='Dasu';
I know I could write the query like that and get result, but I dont want to be writing the values. 我知道我可以这样写查询并得到结果,但是我不想写值。 These values are from another record with user_name 'sys' in the same table. 这些值来自同一表中具有user_name'sys'的另一条记录。 I want a query that will update these particular columns in 'Dasu' with values from 'sys'. 我想要一个查询,该查询将使用“ sys”中的值更新“ Dasu”中的这些特定列。
Any idea? 任何想法?
In Oracle, you can use merge
with a self-join. 在Oracle中,可以将merge
与自merge
一起使用。 Alternatively, you can write correlated subqueries in the update
: 另外,您可以在update
编写相关的子查询:
update user_data
set (old_status, user_group, default_rate, entity_num) = (select old_status, user_group, default_rate, entity_num from user_data where user_name = 'sys')
where user_name='Dasu';
You can nest a select in your update statement. 您可以将选择嵌套在更新语句中。 For Example: 例如:
UPDATE Dasu
SET old_status = (SELECT old_status FROM sys WHERE Id = 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.