Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Comparação de célula a célula no Sql Server?

select T1.id, T1.tbl1, T2.tbl2
from (
       select U.id, U.tbl1, U.col
       from tbl1
         unpivot (tbl1 for col in (c1, c2, c3)) U
     ) T1
  inner join 
     (
       select U.id, U.tbl2, U.Col
       from tbl2
         unpivot (tbl2 for col in (c1, c2, c3)) U
     ) T2
    on T1.id = T2.id and
       T1.col = T2.col
order by T1.id