unisci le due tabelle. invece di

.. FROM tab1 ..

metti

.. FROM (SELECT data, codice FROM tab1 UNION SELECT data, codice FROM tab2) tabx ..