Subject Re: [firebird-support] duplicate string fields?
Author Woody
ifitsx wrote:
> I have built a new 1.54 db, importing data from many tables.
> I want to find records that have a duplicate string field.
> I have tried the following, but it returns an error:
>
> select noteid, folderid, subject
> from dbnotes
> group by subject
> having count(*) > 1
>
> Noteid and folderid are primary and secondary keys.
>
> I need to find any duplicate subject fields and show their folderid.
> The above script returns the following error:
>
> ISC ERROR CODE:335544569
>
> ISC ERROR MESSAGE:
> Dynamic SQL Error
> SQL error code = -104
> Invalid expression in the select list (not contained in either an
> aggregate function or the GROUP BY clause)
>
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


HTH
Woody (TMW)