your current request is approved for insertion, but if you want to prohibit insertions, if this combination already exists, just add the primary key to table4 containing these 2 columns.
In the request, run:
INSERT INTO table4( id1, id3) SELECT id1, id3 FROM table2 INNER JOIN table1 ON table1.id2 = table2.id2 INNER JOIN table3 ON table2.name2 = table3.name3 WHERE name2 LIKE 'input' ON DUPLICATE KEY UPDATE id1=id1;
which is intended only to fulfill the request, if there is a duplicate, it will not do anything.
source share