asmyatt
asked on
SQL - compare data between two tables
I have two tables that contain the same fields: LoanNumber, LoanAmount
I need a query that gives me all records where the LoanNumber matches, but the LoanAmount is different.
What's wrong with my code below? Thanks!
I need a query that gives me all records where the LoanNumber matches, but the LoanAmount is different.
What's wrong with my code below? Thanks!
select LoanNumber, loanamount
from tableA
where (tableA.LoanNumber in
(select loannumber from tableB)
and tableA.loanamount <> tableB.loanamount)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No offense intended but that is really not that good of a query.
SELECT A.loannumber
,A.loanamount AS LoanAmountA
,B..loannumber AS LoanAmountB
FROM tablea A
INNER JOIN tableb B
ON A.loannumber = B.Lloannumber
WHERE A.loanamount <> B.loanamountb;
Where loanamount <> loanamountb
This will only work if table b doesn't have loan numbers that are not in tablea