Possible duplicate:
How to "paste if does not exist" in MySQL?
There is an 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 arrays of PHP arr1[]=array("abc","bcd")and arr2[]=array("abc","cde").
Say I saved the values โโof arr1 [] in an SQL table. Suppose now that I need to store the values โโof arr2 [] in the same SQL table. What SQL INSERT query should I write to avoid duplicating the saving of the "abc" record? The result should be:
MyTable:
1 | abc
2 | bcd
3 | cde
but NOT:
MyTable:
1 | abc
2 | bcd
3 | abc
4 | cde
UPDATE: Maybe MyTable should be created / defined so that duplicate entries are ignored?
source
share