Skip to content
Advertisement

How to insert new row without duplicating existing data

I want to insert rows in my table like so: my columns are student,subject,class,teacher,level. Primary key is (student,subject). The table contains all the students, but the Math subject is missing for some of them, so I want to add it without duplicating the ones that already have it.

I’ve tried this but it gives me unique constraint violated:

Advertisement

Answer

I think you basically need select distinct:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement