Hi everybody! Today i'm facing this problem, i'm trying to write a query that:
- select from a tab (called "FC") all the records that have a YES/NO field (called "Transfer") on YES
- since this tab has a field ("Id_paz") that is FK on another tab ("Pazienti", where the corresponding PK is "CodFisc"), append the corresponding records (actually, just some fields i need) from the "Pazienti" tab into another called "Pazienti_BB"
- but BEFORE THAT, it should check that in "Pazienti_BB" there aren't already records equal to those one it is going to add, and in that case skip to the following record (in order to avoid error messages, since CodFisc in PK also in Pazienti_BB)
Now, i wrote a query that cover the first two points:
INSERT INTO Pazienti_BB
SELECT CodFisc AS CodFisc, Cognome AS Cognome, Nome AS Nome, Genere AS Genere, Data_nascita AS Data_nascita
FROM Pazienti
WHERE CodFisc IN (SELECT Id_paz
FROM FC WHERE FC.Transfer = TRUE);
But for the third point i'm clueless.......any idea? Have i explained myself??
Thanks!!