Trying to do a diff of 2 tables with same data layout and have mismatch records on sameline
Table1 Table2
------ ------
CUSTOMER PART CUSTOMER PART
CUSTID1 PART1 CUSTID1 PART1
CUSTID1 PART2 CUSTID1 PART2
CUSTID1 PART3 CUSTID1 PART3
CUSTUD1 PART4
SELECT T1.CUSTID, T1.PART, T2.CUSTID, T2.PART FROM TABLE1 AS T1
LEFT JOIN TABLE2 AS T2 ON T1.CUSTID = T2.CUSTID
WHERE T1.PART <> T2.PaRT
ORDER BY T1.CUSTID
Sometimes the output look like below – it shows a mismatch when there isn’t one.
CAn I order the tables before the join to get the data to line up ?
Thanks
CUSTID1 PART1 CUSTID1 PART3
CUSTID1 PART2 CUSTID1 PART1
CUSTID1 PART3 CUSTID1 PART2
CUSTUD1 PART4 NULL NULL
You need to do something like:
There’s no need to use left outer join. The order by clause doesn’t make any difference in result of join; it just orders the result.