tags:

views:

33

answers:

2
insert ignore table ( field2 , name) Values ( 22 , 'value3');

its adding duplicating the value

and table strcture :

+------------------------+------------------+------+-----+---------+----------------+
| Field                  | Type             | Null | Key | Default | Extra          |
+------------------------+------------------+------+-----+---------+----------------+
| ID                     | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| field2                 | int(10) unsigned | NO   | MUL | NULL    |                |
| field2                 | int(10) unsigned | YES  |     | NULL    |                |
| name                   | varchar(90)      | YES  |     | NULL    |                |
+------------------------+------------------+------+-----+---------+----------------+

out put

1  22 2 value2
2  22 2 value2
3  23 2 value3
+1  A: 

Do you have an index on one of the fields that you are inserting? If not, add one.

methodin
+1  A: 

You need a unique index on field2 if you don't want duplicates of field2. INSERT IGNORE ignores the insert if there's an error, without any unique index or constraint on those fields, there will be no errors

If you don't want duplicates on the combination of field2 and name , you'll need a unique index on (field2,name).

nos