I'm trying to insert unique values into a table from a View. I have a table as below: the "fromView" has no unique constraint in passport
id | passport | name | surname | address
1 44543 John Smith xxxxx
2 10001 Mike Thomps avasfa
3 10001 Mike Thomps avasfa
4 10001 Mike Thomps avasfa
5 14221 Robert Martinez lkjij3
my "toTable" has the same data structure but with a unique constraint in passport column.
my insert query is this:
INSERT into toTable (id, passport, name, surname, address)
SELECT (id, passport, name, surname, address)
FROM fromView a
WHERE passport IS NOT NULL AND NOT EXISTS (SELECT *
FROM toTable b
WHERE b.passport = a.passport)
but this give me the error below:
Cannot insert duplicate key row in object 'toTable' with unique index 'toTable_Passport_Unique'.
So, I Don't know how to insert unique values into my table. Thanks in advance