| From: | A_Schnabel(at)t-online(dot)de (Andre Schnabel) |
|---|---|
| To: | "Joseph Shraibman" <jks(at)selectacast(dot)net>, "ML: Postgres SQL" <pgsql-sql(at)postgresql(dot)org> |
| Subject: | Re: WHERE on an alias |
| Date: | 2001-08-29 06:27:12 |
| Message-ID: | 003001c13053$a3c4ff60$0201a8c0@aschnabel.homeip.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
----- Original Message -----
From: "Joseph Shraibman" <jks(at)selectacast(dot)net>
Subject: Re: [SQL] WHERE on an alias
> If I try to put a distinct on in my subselect int the from I get:
>
> ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY
expressions
>
> what does that mean?
You need to (at least) ORDER BY the expression you want to have the
DISTINCT ON.
Tom's example would work fine:
> > select distinct on (ml.f1,ml.f2) * from ut,ml
> > where ut.f1 = ml.f1 and ut.f2 = ml.f2
> > order by ml.f1, ml.f2, ml.f3 desc;
Wrong:
select distinct on (ml.f1,ml.f2) * from ut,ml
where ut.f1 = ml.f1 and ut.f2 = ml.f2
order by ml.f2, ml.f1, ml.f3 desc;
Andre
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Vladimir Terziev | 2001-08-29 07:40:00 | |
| Previous Message | Marc G. Fournier | 2001-08-29 03:44:16 | List archives moved and cleaned up ... |