Is this a bug (in 9.0.4), or have I just gone cross-eyed from too much work? The query: select t0."ICD9", t0."Description", count(*) from (select distinct "Person_Id", "ICD9", "Description" from "PatientDiagnoses") as t0 group by (t0."ICD9", t0."Description") order by count(*) desc limit 10; The error: column "t0.ICD9" must appear in the GROUP BY clause or be used in an aggregate function Huh? FWIW, I'm not providing the "PatientDiagnoses" def because it's a complex query involving 3-way union of 5-way joins--intended for end-user querying. Of note, this query works (and performance is good enough as well): select "ICD9", count(*) from (select distinct "Person_Id", "ICD9" from "PatientDiagnoses") as t0 group by "ICD9" order by count(*) desc limit 10; -- Scott Ribe scott_ribe@xxxxxxxxxxxxxxxx http://www.elevated-dev.com/ (303) 722-0567 voice -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general