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") Nick Upson On 21 March 2012 15:07, Olaf Kluge <[email protected]> wrote: > ** > > > Hello, > > at this time I have create an statement: > > select first 1 a.pfad > > from t_pictures a where status <> 6 and > > (select count(*) from t_pictures where status < 5 and kd_id = a.kd_id and > li_id = a.li_id) = 0 > > into :pfad; > > pfad = path for an file > > Now we have thousands of records in this table and the execution takes some > minutes. How can I make this statement better? I would check If there is > for > a record (unique with kd_id and li_id (primary key reference) one record > with status < 5. If no, I can delete the folder then there is no now no > picture in it. > > Thanks for helping. > > Best regards. > > Olaf > > [Non-text portions of this message have been removed] > > > [Non-text portions of this message have been removed] ------------------------------------ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Visit http://www.firebirdsql.org and click the Resources item on the main (top) menu. Try Knowledgebase and FAQ links ! Also search the knowledgebases at http://www.ibphoenix.com ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/firebird-support/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/firebird-support/join (Yahoo! ID required) <*> To change settings via email: [email protected] [email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
