views:

63

answers:

2

hi

i have 2 tables:

Mal: IdNum,Name

Trap: IdNum,Tdate,Name

input: from Tdate to Tdate and Name

i need all the IdNum that in Mal but not in Trap and the input condition

i work on oracle 10g

thank's in advance

+2  A: 
select IdNum from Mal where IdNum not in 
(
   select IdNum from Trap
   where Tdate >= to_date(<dateFrom>, 'yyyymmdd')
   and Tdate <= to_date(<dateTo>, 'yyyymmdd')
   and Name = 'name'
)

...where

= 'name'

could also be

'like', 'contains('

or any other flavour of text comparison.

davek
there is no Tdate from table MAl
Henry Gao
thanks - just noticed that! I'm assuming then that he means "but not in trap and the input condition" rather than "and not in trap" AND "the input condition.
davek
you are trapped again. using not in trap and using Tdate is mutually exclusive condition. if it is not in trap, you do not need Tdate.
Henry Gao
The "NOT IN" refers to the combination of Idnum and date-check, not Idnum in isolation.
davek
+1  A: 
select *
  from mal m
 where not exists (select 1
                     from trap t
                    where m.idnum = t.idnum
                      and t.tdate between <date1> and <date2>
                      and t.name = <name>
                  );
Dougman