Home  >  Article  >  Database  >  数据库批量查询结果作为更新的值

数据库批量查询结果作为更新的值

WBOY
WBOYOriginal
2016-06-07 16:11:191354browse

数据库批量更新。 业务需求: 需要将a表中 type为1 的数据的source_id更新为新的id。 因为之前的id是存储在p_server中,现在更新到了server_info表中 update a set source_id = s.server_id from (select p_server.p_id,p_server.index_code,server_info.ser

数据库批量更新。

业务需求:

需要将a表中 type为1 的数据的source_id更新为新的id。

因为之前的id是存储在p_server中,现在更新到了server_info表中

update a set source_id = s.server_id  from 
(select p_server.p_id,p_server.index_code,server_info.server_id 
from p_server join server_info 
on p_server.index_code = server_info.index_code) s where 
a.source_id = s.p_id
and type = 1;


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn