Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...The forum looks great! You guys have done a fantastic job on arranging things there...Your site is very precise and fun to visit..."

Geography

Where in the world do Tek-Tips members come from?
eshie003 (Programmer)
26 Apr 12 14:41
Hi,

I need to capture only those records from Table 1 where there is no match on Table 2 on criteria below:

TABLE 1.[Agency]=TABLE 2.[Agency] AND
TABLE 1.[Type]=TABLE 2.[Type] AND
TABLE 1.[Code]<>=TABLE 2.[Code]


TABLE 1        
CODE    AGENCY    TYPE
H2015HO    MCO    MA
90801    MCO    MA

TABLE 2        
CODE    AGENCY    TYPE
90801    FFS    MD
90801    MCO    MA
90802    FFS    MD
90802    MCO    MA
90801GT    FFS    MD
90801GT    MCO    MA
H2015HO    MCO    MD
H2015HO    MCO    PHD

FINAL RESULT WANTED        
CODE    AGENCY    TYPE
H2015HO    MCO    MA


Please help as I've tried a number of different queries and am not getting the correct results!  Thanks in advance...
bborissov (Programmer)
26 Apr 12 14:52
What is this sign <>=?
 

Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.

eshie003 (Programmer)
26 Apr 12 14:55
Sorry, typo.  Should read TABLE 1.[Code]<>TABLE 2.[Code]  
bborissov (Programmer)
26 Apr 12 14:57
BTW this should (not tested though) give you the result you ask:

CODE

SELECT Table1.*
FROM Table1
LEFT JOIN Table2 ON  TABLE1.Agency = TABLE2.Agency AND
                     TABLE1.Type   = TABLE2.Type   AND
                     TABLE1.Code   = TABLE2.Code
WHERE TABLE2.Code IS NULL
And:
JOINs ALWAYS works as they should, but not ALWAYS as you you wish for smile

 

Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.

eshie003 (Programmer)
26 Apr 12 15:33
I just tested it and it works!  I can't believe how I missed something as simple as this...

Thank you, thank you!  smile

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close