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!
select LoanNumber, loanamount
from tableA
where (tableA.LoanNumber in 
             (select loannumber from tableB) 
              and tableA.loanamount <> tableB.loanamount)

Open in new window

LVL 2
asmyattAsked:
Who is Participating?
 
Aaron TomoskySD-WAN SimplifiedCommented:
Select loannumber, loanamount, (select loanamount from tableb where loannumber=tablea.loannumber) as loanamountb from tablea
Where loanamount <> loanamountb
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
Select loannumber, loanamount, (select loanamount from table b) as loanamountb from tablea
Where loanamount <> loanamountb

This will only work if table b doesn't have loan numbers that are not in tablea
0
 
8080_DiverCommented:
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;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.