How to insert into the table if the record does not exist, for example the table_materia_materia, has the following information:
+----+-------+---------+
| ID | turma | materia |
+----+-------+---------+
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 2 |
If you try to insert material 1 with class 1 it will check if it has, if you do not give the insert, if it has not it did not insert