Programming glitches have nothing to do with UNIQUE INDEXES in a database table: unless the database engine is stuffed.
The error message arrises because you have not included the 'IGNORE' keyword in your query. INSERT QUERY .
There are lots of ways to do most things, but usually only one or two that are worth using.
rule 1
If you want to guarantee that data in a table is unique then only a unique index is guaranteed to work.
Without it, you may write code that does not cause duplicates, but then the next guy writes bad code and all your efforts are wasted. I think your current predicament is proof of that.
You could do this with 2 simple select queries that use the DISTINCT keyword, but then your second query would have to use a left join with is null to elliminate duplicates across the tables. Difficult join to write when it is multi-column unqueness we are after.
You could also combine those 2 queries into 1 union query, but would still have to include the join/is null and that could get really ugly.
So my only choice would be 3 queries. 1 to create the table with the unique multi-column index, and then 2 simple selects with the ignore keyword.