---
title: "两表（多表）关联update 写法"
author: "wlbbswl"
date: "2012-08-09T14:57:57Z"
tags: []
categories: ["数据库"]
slug: "update"
draft: false
lastmod: "2012-08-09T14:57:41Z"
id: 1626663
url: "https://wlbbswl.iteye.com/blog/1626663"
---

update customers a  
   set    city\_name=(select b.city\_name from tmp\_cust\_city b where b.customer\_id=a.customer\_id)  
   where  exists (select 1  
                  from   tmp\_cust\_city b  
                  where  b.customer\_id=a.customer\_id  
                 )

   -- update 超过2个值  
   update customers a   
   set    (city\_name,customer\_type)=(select b.city\_name,b.customer\_type  
                                     from   tmp\_cust\_city b  
                                     where  b.customer\_id=a.customer\_id)  
   where  exists (select 1  
                  from   tmp\_cust\_city b  
                  where  b.customer\_id=a.customer\_id  
                 )