You will need a UNION
between the full contents of table A and you can use a LEFT JOIN
between A and B to look for non-existing records based on ID_P Name
for the other half of the UNION
.
Use literal NULL
s to fill the columns that do not exist in the B side of the union, to produce the same column set.
-- Take all the cols from table A
SELECT
ID,
ID_P,
IP_Type,
Name
FROM tableA
-- Combine with a filtered set from B
UNION
SELECT
NULL AS ID,
b.ID_P,
NULL AS ID_Type,
b.name
FROM
tableB b
-- Join on ID_P and Name
LEFT JOIN tableA a ON b.ID_P = a.ID_P AND b.Name = A.Name
-- NULLs on the left join mean non-matching
WHERE a.ID_P IS NULL
Here it is in action
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…