Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SQL - compare data between two tables

Posted on 2011-04-22
3
Medium Priority
?
305 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

0
Comment
Question by:asmyatt
  • 2
3 Comments
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 35449860
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
 
LVL 39

Accepted Solution

by:
Aaron Tomosky earned 2000 total points
ID: 35449867
Select loannumber, loanamount, (select loanamount from tableb where loannumber=tablea.loannumber) as loanamountb from tablea
Where loanamount <> loanamountb
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 35450407
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question