Subject | Re: A complicated subquery slows down the main query |
---|---|
Author | Svein Erling |
Post date | 2003-12-10T08:31:03Z |
Maciek, I think Fb 1.5 does this better than Fb 1.0.3, but I am still
on Fb 1.0.2 and the way I would have written a query like this would
be
SELECT <columns> FROM ATable
WHERE EXISTS(
SELECT * FROM AnotherTable a1
JOIN AnotherTable a2 on a2.AKey = a1.AKey
WHERE a1.AKey = ATable.AKey
AND a2.PKey > a1.PKey)
Of course, this is only feasible to replace 'having count(*) > 1' or
similar, if you ever use 'having count(*) = 1000' then this is not the
way to do things ;o)
HTH,
Set
on Fb 1.0.2 and the way I would have written a query like this would
be
SELECT <columns> FROM ATable
WHERE EXISTS(
SELECT * FROM AnotherTable a1
JOIN AnotherTable a2 on a2.AKey = a1.AKey
WHERE a1.AKey = ATable.AKey
AND a2.PKey > a1.PKey)
Of course, this is only feasible to replace 'having count(*) > 1' or
similar, if you ever use 'having count(*) = 1000' then this is not the
way to do things ;o)
HTH,
Set
> I have a problem with the performance of some of the queries I do.
> They are all basically of the same type:
>
> SELECT * from Atable WHERE AKey IN
> (select aKey
> from AnotherTable
> group by aKey
> having count(*) > 1)