基于子查询向 MySQL 插入大量行......遇到麻烦
因此,我想做的是为表中存在的每个国家/地区插入一行 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'tspecify target table 'countries2' for update in FROM Clause
但它也引发了错误:
Subquery returns more than 1 row
So, what I am trying to do is insert a row of NONE, $country for every country that exists in the table.
It should look like
Afghanistan, NONE
Albania, NONE
Andorra, None
...
That is, in addition to the provinces listed for each country... they look like this:
| 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
This is the code I am attempting, but failing miserably.
insert into countries2 (province,country)
VALUES ('NONE', (select distinct country from countries2));
I just get
You can't specify target table 'countries2' for update in FROM clause
But it is also throwing the error:
Subquery returns more than 1 row
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想检查字段的顺序!
you may want to check the order of the fields !
我猜您实际上只想更新此处的现有表?
尝试
I'm guessing that you actually just want to update the existing table here?
Try