Subject | Re: [firebird-support] Query help |
---|---|
Author | Helen Borrie |
Post date | 2012-07-22T22:12:31Z |
>Den 2012-07-22 22:35 skrev Ricardo Uzcategui såhär:At 09:51 AM 23/07/2012, Kjell Rilbe wrote:
>> Maybe if you do a join...
>>
>> like this...
>>
>> select m.* from master m
>> join detail d
>> on (m.id = d.master)
>> where (d.removed is not null)
>
>Thanks for trying, but that would return all master records where thereselect m.* from master m
>is at least one detail that's not removed. Instead, I need all the
>masters where there are removed details, but no current ("unremoved") ones.
join detail d
on (m.id = d.master)
where d.removed is null
and (not exists
(select 1 from detail d2
where d2.master = m.id
and d2.removed is not null))
I think you said that detail.master is not a declared FK. Do you have ascending and descending indexes on it, though?
./hb