Dovresti fare la UNION di A e B
Poi fai una SELECT DISTINCT sulla UNION