Subject Re: [firebird-support] duplicate string fields?
Author Ann W. Harrison
Woody wrote:
> ifitsx wrote:
>>
>> I want to find records that have a duplicate string field.
>>
> The clue is in the error message. "(not contained in either an aggregate
> function .. )"
> The having clause is only used for aggregate queries which contain,
> among other things, counts, sums, etc. Change your query to include the
> count(*) and also change the group by to include all non-aggregate fields:
>
> select noteid, folderid, subject, count(*)
> from dbnotes
> group by noteid, folderid, subject
> having count(*) > 1


Err, if you group by the primary key, you're seldom going to find a
group with more than one member. Here's an alternative:

select a.noteid, a.folerid, b.noteid, b.folderid, a.subject
from dbnotes a
join dbnotes b on (a.subject = b.subject)
where a.noteid < b.noteid

Good luck,


Ann