Subject RE: [firebird-support] Question about better performance Query
Author Svein Erling Tysvær
>>try:
>>
>>select first 1 a.pfad
>>from t_pictures a where status <> 6 and
>>not exists (select 1 from t_pictures where status < 5 and kd_id = a.kd_id
>>and li_id = a.li_id)
>>into :pfad;
>>
>>(also first 1 will return just 1 record but it could be any record in the
>>set as you have no "order by")
>
>The query takes still one minute. Here the ddl of the table, at this time >
>100000 records, for each unique id 30 records (30 pictures and the path)

The plan would be interesting, so would some information about how common various values for STATUS is.

A query you could try (virtually identical to Nicks, the only real change is for a.status):

select a.pfad
from t_pictures a
left join t_pictures b
on a.kd_id = b.kd_id
and a.li_id = b.li_id
and b.status < 5
where (a.status > 6
or a.status = 5)
and b.id is null
rows 1
into :pfad;

HTH,
Set