Subject | Re: [firebird-support] Index suggestion |
---|---|
Author | Milan Tomeš - Position |
Post date | 2010-03-26T09:55:52Z |
Hi,
Dne 26.03.2010 10:39, Arno Brinkman napsal(a):
AREA_IDs are eliminated by GROUP BY clause.
but I need only AREA_IDs that exists more than once (in next step I'm
updating NAME_TYPE to value 'E' to get only one record for every
condition AREA_ID = xxx and NAME_TYPE = 'B'). I don't have a table with
distinct values of AREA_IDs.
Thanks
Milan
Dne 26.03.2010 10:39, Arno Brinkman napsal(a):
> Hi,You're right. There is no reason to use DISTINCT in that query. Multiple
>
>
>> SELECT DISTINCT AREA_ID
>> FROM TMP_CKRAJ
>> WHERE
>> (ID_CCOUNTRY = 'CZE') AND
>> (NAME_TYPE = 'B')
>> GROUP BY AREA_ID
>> HAVING
>> (COUNT(AREA_ID)> 1)
>>
>> It's easy to make an index for ID_CCOUNTRY and NAME_TYPE, but is there
>> any chance to help engine with index that can be used for DISTINCT/GROUP
>> BY/HAVING COUNT ?
>>
> Compound index on (ID_CCOUNTRY, NAME_TYPE) looks most usefull to me, but i don't see the usage of DISTINCT in your query
> here.
>
AREA_IDs are eliminated by GROUP BY clause.
> Also think of the next possible approach for your query:I guess this will not work. This will select all AREA_IDs that exists,
>
> SELECT
> aa.AREA_ID
> FROM
> Table_All_Area aa
> WHERE
> EXISTS(SELECT 1 FROM TMP_CKRAJ tc WHERE
> tc.ID_CCOUNTRY = 'CZE' and
> tc.NAME_TYPE = 'B' and
> tc.AREA_ID = aa.AREA_ID)
>
>
but I need only AREA_IDs that exists more than once (in next step I'm
updating NAME_TYPE to value 'E' to get only one record for every
condition AREA_ID = xxx and NAME_TYPE = 'B'). I don't have a table with
distinct values of AREA_IDs.
Thanks
Milan