group by / having

From: "Alain TESIO" <tesio(at)easynet(dot)fr>
To: <pgsql-sql(at)postgreSQL(dot)org>
Subject: group by / having
Date: 1999-12-19 16:04:40
Message-ID: 00cb01bf4a3a$c6046a80$f15f72c3@atesio
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

Do you know why this command doesn't work ?

> select * from T;
x|y
-+-
1|1
1|2
2|1
2|2
2|3

> select X,Y from T group by X having Y=min(Y);

ERROR: Illegal use of aggregates or non-group column in target list

My goal is quite simple : get only one line per X value (the value which is
returned for Y is not important as long as it's one of the values linked to
the right X).

The query "select X,Y from T group by X" works under MySQL and
returns exactly what I want, how can I do it in PostgreSQL ?

Thanks for your help,
Alain

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 1999-12-19 16:54:55 Re: [SQL] group by / having
Previous Message Alain TESIO 1999-12-19 14:28:59 group by / having