Solved

Need assistance with a Query where records do not match.

Posted on 2014-01-27
2
318 Views
Last Modified: 2014-02-11
Hi Experts,
I need help with a query.  I need to find records in TABLE_A that don't match records in TABLE_B.  The qualifying criteria is where TABLE_A.RECORDNUMBER, TABLE_A.AMOUNT, and TABLE_A.DATE do not match TABLE_B.RECORDNUMBER, and TABLE_B.AMOUNT, and TABLE_B.DATE.  How can I accomplish this?  Thanks in advance.

mrotor
0
Comment
Question by:mainrotor
2 Comments
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 39812853
SELECT a.*
FROM TABLE_A a
   -- the LEFT JOIN insures that all rows in Table_A are in the result set...
   LEFT JOIN TABLE_B b ON a.RECORDNUMBER = b.RECORDNUMBER
      AND a.AMOUNT = b.AMOUNT
      AND a.DATE = b.DATE
-- ... where there is not a match in all three keys
WHERE (b.RECORDNUMBER IS NULL OR b.AMOUNT IS NULL OR b.DATE IS NULL)
0
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 250 total points
ID: 39813471
what Jim Horn suggested will definetly work, as in the case of most of the problems there is an alternative solution available for this as well

Alternative solution

select * from Table_A A
WHERE NOT EXISTS ( SELECT 1 FROM TABLE_B B 
WHERE B.RecordNumber  = A.RecordNumber and B.amount = A.Amount and B.date = A.date
)

Open in new window

0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.

808 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