Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need assistance with a Query where records do not match.

Posted on 2014-01-27
2
322 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

840 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