By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tab_Def(
col_1 INT,
col_2 varchar(10) );
insert into tab_Def values
(101,'ABC'),
(102,'ABC'),
(101,'XYZ');
CREATE TABLE tab_Prod(
col_1 INT,
col_2 varchar(10) );
insert into tab_Prod values
(-101,'ABC'),
(102,'ABC'),
(-101,'XYZ');
Records: 3 Duplicates: 0 Warnings: 0
Records: 3 Duplicates: 0 Warnings: 0
with tab_Def as (
select col_1,
col_2,
row_number() over() as row_num
from tab_Def
), tab_Prod as (
select col_1,
col_2,
row_number() over() as row_num
from tab_Prod
) select td.col_1,
td.col_2,
tp.col_1
from tab_Def td
inner join tab_Prod tp on td.row_num=tp.row_num
where td.col_1 <> tp.col_1
col_1 | col_2 | col_1 |
---|---|---|
101 | ABC | -101 |
101 | XYZ | -101 |