One to many query parameter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two tables to join. T1 has the header type information and T2 has the
detail, hence the one to many. Now I want to join the two tables in a query
and return only the entries in T1 where any one record in its detail in T2
contains a zero value:
T1 T2
----- -----
entry1 Detail1 is >0
entry1 Detail2 is >0 (I don't want entry1)

entry2 Detail1 is >0
entry2 Detail2 is >0
entry2 Detail3 is =0 ( I want entry2)

How do I do that?
 
I have two tables to join. T1 has the header type information and T2 has the
detail, hence the one to many. Now I want to join the two tables in a query
and return only the entries in T1 where any one record in its detail in T2
contains a zero value:
T1 T2
----- -----
entry1 Detail1 is >0
entry1 Detail2 is >0 (I don't want entry1)

entry2 Detail1 is >0
entry2 Detail2 is >0
entry2 Detail3 is =0 ( I want entry2)

How do I do that?


The post does not specify upon which column T1 and T2 will be joined.
So let's stipulate that the primary key of T2 is a composite key
containing the primary key to T1.

If that is the case, would not the query be as below?

select T1.*
from T1
where exists
( select 'true'
from t2
where Master_key = T1.Master_key
and Detail_value = 0 )
 
Right. In my example the two fields joined in each table would be T1 entry1
and T2 entry1.
 
Right. In my example the two fields joined in each table would be T1 entry1
and T2 entry1.
Your response was timely and right on. I am very pleased with the results.
It worked.> --
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top