I have a query which retrieve from few tables but 2 tables having same field value,
Query is
SELECT A.NUM_RIF, B.NDG, D.NDG FROM ICGR1100 A
LEFT JOIN (ICGR1105 E INNER JOIN ICGR1101 D ON E.C_IST=D.C_IST AND E.DT_DOM_NDG=D.DT_DOM_NDG AND E.N_DOM=D.N_DOM) ON A.C_IST=E.C_IST AND A.NUM_RIF=E.NUM_RIF
LEFT JOIN ICGR1103 B ON A.C_IST=B.C_IST AND A.NUM_RIF=B.NUM_RIF
Result is:
NUM_RIF NDG NDG
---------------- ---------------- ----------------
0000000000000981 (null) 0000000000002490
0000000000000985 (null) 0000000000002490
0000009000004523 0000000000001775 (null)
0000009000004521 0000000000001775 (null)
0000009000004218 0000000000001775 (null)
0000000000000980 (null) (null)
0000009000004914 0000000000002490
0000009000004917
0000009000004923 0000000000002490
So my expectation result is as below:
NUM_RIF NDG
---------------- ----------------
0000000000000981 0000000000002490
0000000000000985 0000000000002490
0000009000004523 0000000000001775
0000009000004521 0000000000001775
0000009000004218 0000000000001775
0000000000000980 (null)
0000009000004914 0000000000002490
0000009000004914
0000009000004923 0000000000002490
the case is both field might have empty value, or null, or either one will be empty/null, but so far don’t have value in both field, which mean only one field have value
Most dbmss have a NVL like function:
Will return B.NDG if not null otherwise D.NDG
NVL is for Oracle but there’s probably an equivalent for your dbms