I am having problem when trying to insert record where i do not want duplicates. This problem is different from any solution i found in google so here it goes:
I have TABLE1 and TABLE2 and i want to insert record from TABLE1 into TABLE2 so i use this query:
INSERT INTO table1
SELECT *
FROM table2
WHERE table2.importId NOT IN
(
SELECT importId
FROM table1
);
This works only if TABLE2 is guaranty does not contain duplicates importId. So if TABLE2 has duplicates importId and i want to insert into TABLE1 which doesn't contain importId from TABLE2. The script above will persist on inserting records thus creating duplicates importId in TABLE1.
I already tried:
INSERT INTO table1
SELECT *
FROM table2
WHERE NOT EXIST
(
SELECT importId
FROM table1
WHERE table1.importId <> table2.importId
);
Same results occurs! Now i am having to write another query to remove duplicates. So is there a way round this problem?
I use MYSQL in phpmyadmin BTW.