title: MYSQL - Duplicate entry '0' for key 'PRIMARY'
body: <p>I have a parent table Customers and a child table Addresses. When I created Customers I left ADDRESS reference ID 0 so I could fill it in later. Well now is the time insert the ADDRESSES id's into Customers but when I run the command I get a duplicate error, even though there isn’t any. </p>
  
  <pre><code>insert into Customers (ADDRESS) select ID from Addresses ;
  ERROR 1062 (23000): Duplicate entry '0' for key 'PRIMARY'
  </code></pre>
  
  <p>Customers</p>
  
  <pre><code>+---------+---------------+------+-----+---------+-------+
  | Field   | Type          | Null | Key | Default | Extra |
  +---------+---------------+------+-----+---------+-------+
  | ID      | int(11)       | NO   | PRI | NULL    |       |
  | NAME    | varchar(20)   | NO   |     | NULL    |       |
  | AGE     | int(11)       | NO   |     | NULL    |       |
  | ADDRESS | int(11)       | NO   |     | NULL    |       |
  | SALARY  | decimal(18,2) | YES  |     | NULL    |       |
  +---------+---------------+------+-----+---------+-------+
  5 rows in set (0.00 sec)
  </code></pre>
  
  <p>Addresses</p>
  
  <pre><code>+------------+-------------+------+-----+---------+----------------+
  | Field      | Type        | Null | Key | Default | Extra          |
  +------------+-------------+------+-----+---------+----------------+
  | ID         | int(11)     | NO   | PRI | NULL    | auto_increment |
  | CUSTOMERID | int(11)     | NO   |     | NULL    |                |
  | CITY       | varchar(35) | YES  |     | NULL    |                |
  | COUNTRY    | varchar(45) | YES  |     | NULL    |                |
  +------------+-------------+------+-----+---------+----------------+
  4 rows in set (0.02 sec)
  </code></pre>
  
  <p>Customers</p>
  
  <pre><code>+----+--------+-----+---------+---------+
  | ID | NAME   | AGE | ADDRESS | SALARY  |
  +----+--------+-----+---------+---------+
  |  0 | Matt   |  24 |       0 | 2200.00 |
  |  1 | Andrew |  23 |       0 | 4400.00 |
  |  2 | John   |  30 |       0 | 1200.00 |
  |  3 | Mike   |  55 |       0 | 5500.00 |
  |  5 | George |  45 |       0 | 2300.00 |
  |  6 | Frank  |  32 |       0 | 2300.00 |
  |  7 | George |  45 |       0 | 2700.00 |
  |  8 | Joe    |  38 |       0 | 4350.00 |
  |  9 | Josh   |  35 |       0 | 5050.00 |
  +----+--------+-----+---------+---------+
  </code></pre>
  
  <p>Addresses </p>
  
  <pre><code>+----+------------+----------+---------+
  | ID | CUSTOMERID | CITY     | COUNTRY |
  +----+------------+----------+---------+
  | 15 |          0 | Chicago  | USA     |
  | 16 |          1 | Chicago  | USA     |
  | 17 |          2 | London   | ENG     |
  | 18 |          3 | New York | USA     |
  | 19 |          5 | New York | USA     |
  | 20 |          6 | New York | USA     |
  | 21 |          7 | Chicago  | USA     |
  | 23 |          8 | Miami    | NULL    |
  | 25 |          9 | Miami    | NULL    |
  </code></pre>