Subject | Re: [firebird-support] Optimizing query |
---|---|
Author | Woody |
Post date | 2010-07-09T20:55:02Z |
From: "Ismael L. Donis GarcĂa" <ismael@...>
Sent: Friday, July 09, 2010 3:05 PM
To: <firebird-support@yahoogroups.com>
Subject: [firebird-support] Optimizing query
for the inner select subquery.
Try this: (not tested)
select a.idedoc, a.documento, a.docemp, a.fecha as fec, a.debe as ded,
a.antdeb, a.nota, b.factura, b.fecha, b.debe
from pafacpag a
left join pafacpag b on (a.idedoc = b.idedoc) and (b.entidad = '2578') and
(b.debe > 0) and (b.clave = 'PS')
where (((a.fecha) < '2009/12/31') and ((a.debe) > 0) and ((a.entidad) =
'2578') and ((a.factura) = 'PA') and ((a.clave) = 'PO'))
order by a.docemp, a.fecha, b.fecha
HTH
Woody (TMW)
Sent: Friday, July 09, 2010 3:05 PM
To: <firebird-support@yahoogroups.com>
Subject: [firebird-support] Optimizing query
> I have the following query, but it takes long.You are joining a table to itself. Even so, I don't think there is a need
>
> Does any way exist of optimizing response time?
>
> select a.idedoc, a.documento, a.docemp, a.fecha as fec, a.debe as ded,
> a.antdebe, a.nota, b.factura, b.fecha, b.debe
> from pafacpag a left join (select c.idedoc as ide, c.factura, c.fecha,
> c.debe from pafacpag c where (((c.entidad)='2578')
> and ((c.debe)>0) and ((c.clave)='PS'))) as b on a.idedoc = b.ide where
> (((a.fecha)<'2009/12/31') and
> ((a.debe)>0) and ((a.entidad)='2578') and ((a.factura)='PA') and
> ((a.clave)='PO')) order by a.docemp, a.fecha, b.fecha
>
for the inner select subquery.
Try this: (not tested)
select a.idedoc, a.documento, a.docemp, a.fecha as fec, a.debe as ded,
a.antdeb, a.nota, b.factura, b.fecha, b.debe
from pafacpag a
left join pafacpag b on (a.idedoc = b.idedoc) and (b.entidad = '2578') and
(b.debe > 0) and (b.clave = 'PS')
where (((a.fecha) < '2009/12/31') and ((a.debe) > 0) and ((a.entidad) =
'2578') and ((a.factura) = 'PA') and ((a.clave) = 'PO'))
order by a.docemp, a.fecha, b.fecha
HTH
Woody (TMW)