Subject | Query optimalisation |
---|---|
Author | mariuszstefaniak |
Post date | 2009-07-07T17:27:11Z |
I have three tables:
A, with customers data and B and C with operations.
Records from A are used in B and C tables.
I'd like to count, how many times every customer (A) was used in both tables B and C.
I have written a query, but it's not too effective. (table A
it'd about 150 thousands of records, B - 75 thousands, C - 120 thousands).
Have anyone any idea how to optimise this query?
(firebird 2.1)
select A.id_cust, A.name, count(together.id_cust)
from A
left join
(
select id_cust from B
union all
select id_cust from C
) together on together.id_cust=A.id_cust
group by A.id_cust, A.name
order by A.name
regards
Mariusz
A, with customers data and B and C with operations.
Records from A are used in B and C tables.
I'd like to count, how many times every customer (A) was used in both tables B and C.
I have written a query, but it's not too effective. (table A
it'd about 150 thousands of records, B - 75 thousands, C - 120 thousands).
Have anyone any idea how to optimise this query?
(firebird 2.1)
select A.id_cust, A.name, count(together.id_cust)
from A
left join
(
select id_cust from B
union all
select id_cust from C
) together on together.id_cust=A.id_cust
group by A.id_cust, A.name
order by A.name
regards
Mariusz