Possible Duplicate:
How to 'insert if not exists' in MySQL?
There is SQL table:
CREATE TABLE IF NOT EXISTS `MyTable` (
`id` smallint(6) NOT NULL AUTO_INCREMENT,
`MyVar` varchar(40) DEFAULT NULL,
PRIMARY KEY (`id`)
)
And there are two PHP arrays arr1[]=array("abc","bcd")
and arr2[]=array("abc","cde")
.
Let's say I have saved arr1[] values to SQL table. Now let's suppose I need to save arr2[] values to the same SQL table. Which SQL INSERT query do I need to write in order to avoid duplicate saving of "abc" entry? The result must be:
MyTable:
1 | abc
2 | bcd
3 | cde
but NOT:
MyTable:
1 | abc
2 | bcd
3 | abc
4 | cde
UPDATE: Maybe the MyTable should be created/defined in such a way that duplicate entries are ignored?