Buongiorno, io devo fare una query select ad un database(PostgreSql nel mio caso). Dal momento che ho due tabelle "patient_mapping" e "patient_mapping_test" e devo fare una full join finalizzata a verificare che un certo paziente non sia presente nè nell'una nè nell'altra tabella, ha più senso fare una full join sola od unire i risultati con una union? perchè ho notato che con le singole full join mi vengono restituiti in output risultati diversi a seconda dell'ordine con cui gliele passo alla full join.
AD esempio con questo ordine di tabelle passate ottengo un risultato
codice:
(select coalesce (pm.patient_num,pmt.patient_num) as patient_num,
coalesce (pm.patient_ide_source ,pmt.patient_ide_source) as patient_ide_source
from patient_mapping pm full join patient_mapping_test pmt
on pm.patient_ide = pmt.patient_ide
where pm.patient_ide ='PAT004')
mentre con l'ordine invertito ottengo un altro output:
codice:
(select coalesce (pmt.patient_num,pm.patient_num) as patient_num,
coalesce (pmt.patient_ide_source ,pm.patient_ide_source) as patient_ide_source
from patient_mapping_test pmt full join patient_mapping pm
on pmt.patient_ide = pm.patient_ide
where pmt.patient_ide ='PAT004');
E io stavo pensando,dato che devo verificare se il record non sia presente nè nell'una
nè nell'altra tabella, se non sia più corretto fare cosi:
codice:
(select coalesce (pm.patient_num,pmt.patient_num) as patient_num,
coalesce (pm.patient_ide_source ,pmt.patient_ide_source) as patient_ide_source
from patient_mapping pm full join patient_mapping_test pmt
on pm.patient_ide = pmt.patient_ide
where pm.patient_ide ='PAT004')
union
(select coalesce (pmt.patient_num,pm.patient_num) as patient_num,
coalesce (pmt.patient_ide_source ,pm.patient_ide_source) as patient_ide_source
from patient_mapping_test pmt full join patient_mapping pm
on pmt.patient_ide = pm.patient_ide
where pmt.patient_ide ='PAT004');
In modo da prendere tutte le corrispondenze?
Qualcuno sa dirmi quale tra esse sia la soluzione più corretta ? Grazie