根据子查询向MySQL插入大量行...遇到麻烦

时间:2011-05-11 06:30:16

标签: mysql mysql-error-1093 mysql-error-1242

所以,我要做的是为表中存在的每个国家/地区插入一行NONE,$ country。

应该看起来像

   Afghanistan, NONE
   Albania, NONE
   Andorra, None

... 也就是说,除了为每个国家列出的省份......它们看起来像这样:

| Zambia                    | Western                                            |
| Zimbabwe                  | Bulawayo                                           |
| Zimbabwe                  | Harare                                             |
| Zimbabwe                  | Manicaland                                         |
| Zimbabwe                  | Mashonaland Central                                |
| Zimbabwe                  | Mashonaland East                                   |
| Zimbabwe                  | Mashonaland West                                   |
| Zimbabwe                  | Masvingo                                           |
| Zimbabwe                  | Matabeleland North                                 |
| Zimbabwe                  | Matabeleland South                                 |
| Zimbabwe                  | Midlands  

这是我正在尝试的代码,但却失败了。

insert into countries2 (province,country) 
VALUES ('NONE', (select distinct country from countries2));

我得到了

You can't specify target table 'countries2' for update in FROM clause

但它也在抛出错误:

Subquery returns more than 1 row

2 个答案:

答案 0 :(得分:1)

insert into countries2 (province,country) 
 select distinct 'NONE', country from countries2

您可能想查看字段的顺序!

答案 1 :(得分:0)

我猜你真的只是想在这里更新现有表格? 试试

UPDATE countries2 SET province = 'NONE'