INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Query (if not exist) in 3 tables

Query (if not exist) in 3 tables

(OP)
Is hope someone can help me.
I have 3 tables (A,B,C)
In Table A there are 2 columns (A.Pkey and A.Name)
In Table B there are 2 columns (B.ID1 and B.ID2) A.Pkey and B.ID1 contains the same unique values
In Table C there are 2 columns (C.ID3 and C.Value) B.ID2 and C.ID3 contains the same unique values (if exists)

I'm searching for the right query for listing all the names where there is NO record in tables C

Thanks in advance

RE: Query (if not exist) in 3 tables

Something like this should work:

CODE

SELECT
  A.Name
FROM 
  A 
  LEFT OUTER JOIN B ON A.Pkey = B.ID1 
  LEFT OUTER JOIN C ON B.ID2 = C.ID3 
WHERE 
  B.ID2 IS NOT NULL 
  AND C.Value IS NULL 

This should select all the names where there IS a record in B, but with NO record in C.

RE: Query (if not exist) in 3 tables

(OP)
Thanks!!! it works perfectly.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

Resources

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