Need help with T sql query
sql, sql-server-2008-r2, t-sql
Solution
select isnull(t1.Col1,t2.Col2) as Col,
t1.Col2 as MismatchValuesInTable1,
t2.Col2 as MismatchValuesInTable2
from t1
FULL JOIN t2 on (t1.Col1=T2.Col1) and (t1.Col2=t2.Col2)
where t1.Col2 is null or t2.Col2 is null
order by Col
SQLFiddle demo
Problem
I have two tables. The data in those are something like below: Table 1: ``` Col1 Col2 ---------------- A A1 A A2 A A3 B B1 B B2 B B3 ``` Table 2: ``` Col1 Col2 ------------------ A A1 A A4 A A5 B B1 B B4 B B5 ``` I need to bring out the difference in data in Col2 of two tables based on the values in Col1. The output should look something like below: Output: ``` Col MismatchValuesInTable1 Mismatchvaluesintable2 --------------------------------------------------------- A A2 A4 A3 A5 B B2 B4 B3 B5 ``` Please help me with a query to achieve the above.