sql >> Base de Datos >  >> RDS >> Sqlserver

¿Comparación de celda a celda en 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