It seems you're creating a so-called join table, for which the purpose is to relate items in table1 to items in table2 many to many.
This is usually done with a two-column table. The two columns in that table are both part of the primary key. You'd do this like so:
CREATE TABLE JoinTable (
first_id INT NOT NULL ,
second_id INT NOT NULL ,
PRIMARY KEY (first_id, second_id),
FOREIGN KEY (first_id)
REFERENCES first(first_id)
ON DELETE CASCADE,
FOREIGN KEY (second_id)
REFERENCES second(second_id)
ON DELETE CASCADE
)
Wnen you do this, you won't be able to insert duplicate values.