0

如果我在另一个表有多个与外键匹配的值时使用 INNER JOIN 更新一个表会发生什么。

     update   
       customer 
     SET  
       customer.chosen_phone = phone.number
     FROM  
      customer c 
     INNER JOIN  
      phone p  
     ON  
      c.id = p.customer_id

customer
--------
id    chosen_phone
--    ------------ 
10    ?

phone
----- 
customer_id  number
-----------  ------
10           555-123-4567
10           888-999-0000
10           111-222-3333

谢谢!

4

2 回答 2

0

在您的情况下,更新将运行 3 次
1) 电话将更新为 555-123-4567
2) 电话将更新为 888-999-0000
3) 电话将更新为 111-222-3333

于 2013-07-05T07:59:34.370 回答
0

I'm not sure what database you are working on. Just tried this in Oracle and it returns an error 'single row sub query returns multiple rows'. As I suggested in the comments on the question, I would suggest looking for ways that you can determine the most appropriate phone number.

于 2013-07-04T16:59:33.200 回答