Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据子查询向MySQL中插入大量行。。。有麻烦_Mysql_Mysql Error 1093_Mysql Error 1242 - Fatal编程技术网

根据子查询向MySQL中插入大量行。。。有麻烦

根据子查询向MySQL中插入大量行。。。有麻烦,mysql,mysql-error-1093,mysql-error-1242,Mysql,Mysql Error 1093,Mysql Error 1242,所以,我要做的是为表中存在的每个国家插入一行NONE,$country 应该是这样的 Afghanistan, NONE Albania, NONE Andorra, None 。。。 也就是说,除了每个国家列出的省份之外。。。它们看起来像这样: | Zambia | Western | | Zimbabwe | Bul

所以,我要做的是为表中存在的每个国家插入一行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));
我只是

不能在FROM子句中为更新指定目标表“countries2”

但它也抛出了一个错误:

Subquery returns more than 1 row

我猜您实际上只是想在这里更新现有的表? 试一试


您可能需要检查字段的顺序

事实上,这个表格包含数千个条目,我只是想把“无”添加到每个国家的省份列表中。完美、独特的“无”。哈哈
UPDATE countries2 SET province = 'NONE'
insert into countries2 (province,country) 
 select distinct 'NONE', country from countries2