From: | "jose' soares" <sferac(at)bo(dot)nettuno(dot)it> |
---|---|
To: | Oliver Elphick <olly(at)lfix(dot)co(dot)uk> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-sql(at)hub(dot)org, pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Re: [SQL] Re: [HACKERS] Re: SELECT DISTINCT ON ... ORDER BY ... |
Date: | 1999-02-02 15:25:19 |
Message-ID: | 36B718DF.53BE37EF@bo.nettuno.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-sql |
Oliver Elphick ha scritto:
> "jose' soares" wrote:
> >Yes, seems that SELECT DISTINCT ON is not part of SQL92 but it is very
> >interesting and I think it is something missing to Standard.
> >I don't know how to do the following, if we take off DISTINCT ON from
> >PostgreSQL:
> >
> >db=> select distinct cognome, nome,via from membri where cap = '41010';
> >cognome|nome |via
> >-------+----------------+--------------------------
> >FIORANI|ELISABETTA |VIA PRETI PARTIGIANI, 63
> >FIORANI|GASTONE |VIA PRETI PARTIGIANI, 63
> >FIORANI|MATTIA |VIA PRETI PARTIGIANI, 63
> >FIORANI|SIMONE |VIA PRETI PARTIGIANI, 63
> >GOZZI |LILIANA |VIA MAGNAGHI, 39
> >GOZZI |MATTEO |VIA MAGNAGHI, 39
> >RUSSO |DAVIDE |STRADA CORLETTO SUD, 194/1
> >RUSSO |ELENA TERESA |STRADA CORLETTO SUD, 194/1
> >RUSSO |FORTUNATO |STRADA CORLETTO SUD, 194/1
> >RUSSO |MAURIZIO ANTONIO|STRADA CORLETTO SUD, 194/1
> >(10 rows)
> >
> >db=> select distinct on cognome cognome, nome,via from membri where cap =
> >'41010';
> >cognome|nome |via
> >-------+----------------+--------------------------
> >FIORANI|GASTONE |VIA PRETI PARTIGIANI, 63
> >GOZZI |LILIANA |VIA MAGNAGHI, 39
> >RUSSO |MAURIZIO ANTONIO|STRADA CORLETTO SUD, 194/1
> >(3 rows)
>
> This gives the same results:
>
> junk=> select cognome, nome, via from membri where cap = '41010' group by cognome;
> cognome|nome |via
> -------+----------+--------------------------
> FIORANI|ELISABETTA|VIA PRETI PARTIGIANI, 63
> GOZZI |LILIANA |VIA MAGNAGHI, 39
> RUSSO |DAVIDE |STRADA CORLETTO SUD, 194/1
This is very interesting and useful, I thought it wasn't possible. Seems that standard allows
only the "order by" column(s)
and the aggregate function(s) on target list.
I tried the same query on Informix, also on Ocelot but it gives me an error.
On Informix and Ocelot
queries like:
select cognome, max(age) from membri where cap = '41010' group by cognome;
are allowed.
but
queries like:
select cognome, nome, via from membri where cap = '41010' group by cognome;
aren't allowed.
-Jose'-
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 1999-02-02 15:27:02 | Re: [HACKERS] Postgres Speed or lack thereof |
Previous Message | Thomas G. Lockhart | 1999-02-02 15:00:07 | Re: [HACKERS] VACUUM ANALYZE failed on linux |
From | Date | Subject | |
---|---|---|---|
Next Message | Herouth Maoz | 1999-02-02 15:57:08 | Re: [SQL] Re: [HACKERS] Re: SELECT DISTINCT ON ... ORDER BY ... |
Previous Message | Oliver Elphick | 1999-02-01 16:40:37 | Re: [SQL] Re: [HACKERS] Re: SELECT DISTINCT ON ... ORDER BY ... |