Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query (if not exist) in 3 tables 1

Status
Not open for further replies.

Bigsin

Programmer
Jan 17, 2009
82
0
0
NL
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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top