Expert Answer Center > Expert Knowledgebase > View Answer
EMAIL THIS
Expert Knowledgebase
  EXPERT KNOWLEDGEBASE HOME        RSS FEEDS  
I am using DB2 OS/390 7.1.1. My question is how do I get the difference between what is in table 'A' and not in table 'B'? I have tried using the NOT EXISTS clause without any luck. QUESTION POSED ON: 07 OCT 2004
QUESTION ANSWERED BY: Craig Mullins

Well, if you have a primary key in both tables, the answer would be something like this:

SELECT *
FROM   TableA A
WHERE  A.KEY NOT IN (SELECT B.KEY FROM TableB B);
Of course, if you do not have keys that match between these tables then you'd have to figure out if there are duplicate rows, and what that means to your question. In other words, if you have four exact duplicate rows in TableA and two in TableB, then is this a match (meaning there is no difference) or do you want to return two of the four? And what about the opposite (two in TableA and four in TableB)?

And if there is no key at all, are you wanting to compare every column in TableA against every column in TableB? That might actually be quicker to answer by writing a one-off program.

Related Topics:

Search Advice from more than 250 TechTarget Experts
Your question may have already been answered! Browse or search more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice
ASSOCIATED RSS FEEDS

Expert Answer Center: Expert Q&As
View all RSS Feeds  |  RSS Info

HomeExperts on DemandIT Expert Webcast SeriesExpert KnowledgebaseSite Index
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  RSS  |  Site Map




All Rights Reserved, Copyright 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts