sql - How to get specific mismatched column when using EXCEPT -


i using except / minus compare if rows/columns between 2 tables matching.

select col1, col2 table1 minus select col1, col2 table2 

for given row, if e.g. col2 doesn't match, output col2 ignoring matched col1 value or show null there no mismatches col1. there way sql alone?

table1

| col1 | col2 | |    |  b   | |  x   |  y   | |  m   |  n   | 

table 2

| col1 | col2 | |    |  z   | |  x   |  y   | |  1   |  n   | 

applying above sql produces

| col1 | col2 | |    |  b   | |  m   |  n   | 

but might need mismatched values below.

| col1 | col2 | |      |  b   | |  m   |      | 

you can try this

select case           when t2.col1 null or t1.col1 <> t2.col1 t1.col1         end col1,         case           when t2.col2 null or t1.col2 <> t2.col2 t1.col2         end col2    table1 t1         left join table2 t2           on (t1.col1 = t2.col1               or t1.col2 = t2.col2)             , (t1.col1 <> t2.col1                    or t1.col2 <> t2.col2);  

hope should solve problem.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -