-1

这是我的桌子1

 id  | userid | country

  1  | 25     |    
  2  | 36     |    
  3  | 24     |  
  4  | 24     |   
  5  | 25     |  
  6  | 24     |   

表2

  id   |  country

  25   |   Algeria  
  36   |   Canada
  24   |   Sweden
  15   |   China

WHERE table2.id = table1.userid

所以我的结果将是

  id  | userid | country

  1  | 25     |  Algeria 
  2  | 36     |  Canada 
  3  | 24     |  Sweden
  4  | 24     |  Sweden 
  5  | 25     |  Algeria
  6  | 24     |  Sweden

我的 SQLFIDDLE

我试过这个

 INSERT INTO `table1`(`country`) 
  SELECT m.country from table2 m , table1 v WHERE  m.id = v.userid  

但它什么也没插入。我想知道错误在哪里?.

编辑。

国家字段为空,它只是文件显示空值

4

1 回答 1

3

您应该这样做UPDATE,而不是INSERT因为行已经存在并且您想要修改某些字段。

UPDATE  table1 a
        INNER JOIN table2 b
            ON a.userid = b.id
SET     a.country = b.country
于 2013-07-28T19:18:24.713 回答