0

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
4

2 回答 2

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

you may want to check the order of the fields !

于 2011-05-11T06:40:50.407 回答
0

I'm guessing that you actually just want to update the existing table here? Try

UPDATE countries2 SET province = 'NONE'
于 2011-05-11T06:33:15.447 回答