Insert into MySQL a huge number of rows, based on subquery... having trouble
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 N开发者_JAVA百科orth |
| 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
insert into countries2 (province,country)
select distinct 'NONE', country from countries2
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
UPDATE countries2 SET province = 'NONE'
精彩评论