From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | Chris Albertson <chrisalbertson90278(at)yahoo(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Need SQL help, I'm stuck. |
Date: | 2001-12-10 23:33:59 |
Message-ID: | 20011211103359.B32177@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Dec 10, 2001 at 01:42:54PM -0800, Chris Albertson wrote:
> Help. I seem to have a case of "brain lock" and can't figure out
> something that I should know is simple.
>
> Here is what I am trying to do. Let's say I have a table called
> T1 with columns C1, C2, C3, C4. It contains data as follows
>
> a 1 abcd dfg
> a 2 cvfr erg
> a 3 derg hbg
> b 1 cccc rth
> c 1 rdvg egt
> c 2 derf ett
>
> I want a SQL query that returns these rows
>
> a 3 derg hbg
> b 1 cccc rth
> c 2 derf ett
>
How about:
select distinct on (C1) C1, C2, C3, C4 from T1 order by C1, C2 desc;
--
Martijn van Oosterhout <kleptog(at)svana(dot)org>
http://svana.org/kleptog/
> Terrorists can only take my life. Only my government can take my freedom.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-12-10 23:37:19 | Re: Weird problem - possibly a bug. |
Previous Message | Robert B. Easter | 2001-12-10 23:24:07 | Re: Need SQL help, I'm stuck. |