插入到MySQL行的数量巨大,根据subquery-有麻烦

所以,我所要做的是插入NONE,$国家的一排是存在于表中每一个国家。

它应该看起来像

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

--------------解决方案-------------

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

你可能要检查的字段的顺序!

我猜你其实只是想在这里更新现有的表? 尝试

UPDATE countries2 SET province = 'NONE'

分类:MySQL的 时间:2015-03-15 人气:4
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 2.909 (s). 10 q(s)