We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

SQL - compare data between two tables

Medium Priority
313 Views
Last Modified: 2012-05-11
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

Comment
Watch Question

Aaron TomoskyDirector, SD-WAN Solutions
CERTIFIED EXPERT

Commented:
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
Director, SD-WAN Solutions
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
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

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.