Subject | AW: [firebird-support] finding triple entries |
---|---|
Author | Christian Waldmann |
Post date | 2010-09-10T13:03:32Z |
>>On 10/09/2010 11:10, Christian Waldmann wrote:[Christian Waldmann]
>> Hello SQL experts
>>
>> I have a table with a colum visitId ( and some other culoms)
>>
>> Each visitiId is exactly twice in the tabel. By error there are some
>> visitId more than twice in the table.
>>
>> Who knows an efficent query to find all rows where the visitid is
>> present more than two times?
>>
>> many thanks
>> Christian
>Try this:
>select a_unique_reference,visitid, count(visitid) as DUPLICATES
>from yourtablename
>group by a_unique_reference,visitid
>having count(visitid)>2
>
>a_unique_reference will be some field you can easily identify, such as
>person's name or account id.
>
>--
>Alan J Davies
>Aldis
The final query is perfect and fast
select tav.UIDANIMAL, tav.VISITID, count(*)
from TBLANIMALVISIT tav
group by tav.UIDANIMAL, tav.VISITID
HAVING count(*) >= 3
Many thanks for the perfect, quick answers from Alan and Pepak.
Happy queries
Christian