Re: problem query ...

From: "PG Explorer" <pgmail(at)pgexplorer(dot)com>
To: "Ugly Hippo" <ugly_hippo(at)yahoo(dot)ca>, "John Taylor" <postgres(at)jtresponse(dot)co(dot)uk>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: problem query ...
Date: 2002-02-02 09:15:04
Message-ID: 000c01c1abca$1b4a9260$0c0ba8c0@sabex.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

TRY

SELECT * from mytable where name =(
select max(name) from mytable)
Union
SELECT * from mytable where descrip =(
select max(descrip) from mytable)
Union
SELECT * from mytable where update =(
select max(update) from mytable)

> > I want to return 1 row for each id, that contains
> > the maximum update value for that id, and
> > the values for name and desc.
To return only ONE ROW from each the fields name,descrip and update must be
UNIQUE.

PS
desc is a reserved word for descending.

Hope this helps

http://www.pgexplorer.com
GUI tool for postgres

----- Original Message -----
From: "Ugly Hippo" <ugly_hippo(at)yahoo(dot)ca>
To: "John Taylor" <postgres(at)jtresponse(dot)co(dot)uk>; <pgsql-novice(at)postgresql(dot)org>
Sent: Saturday, February 02, 2002 10:34 AM
Subject: Re: [NOVICE] problem query ...

>
> --- John Taylor <postgres(at)jtresponse(dot)co(dot)uk> wrote:
> >
> > Hi,
> >
> > I hope someone can help with this query, which is
> > causing me great problems.
> >
> > I have a table:
> > create table mytable ( id varchar(10), name
> > varchar(10), desc varchar(10), update integer);
> >
> > I want to return 1 row for each id, that contains
> > the maximum update value for that id, and
> > the values for name and desc.
>
> I would try (I can't connect to my db at the moment):
>
> select id, max(name), max(desc), max(update)
> from mytable
> group by id;
>
> HTH,
> Troy
> ugly_hippo(at)yahoo(dot)ca
>
> >
> > I've tried everything I can think of, but no luck
> > :-(
> > I'm sure there is some simple trick that I'm
> > missing.
> >
> > Can someone please put me out of my misery !
> >
> > Thanks
> > JohnT
> >
> > ---------------------------(end of
> > broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the
> > unregister command
> > (send "unregister YourEmailAddressHere" to
> majordomo(at)postgresql(dot)org)
>
>
> ______________________________________________________________________
> Web-hosting solutions for home and business! http://website.yahoo.ca
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Annie Bai 2002-02-03 00:18:12 existence of user
Previous Message Ugly Hippo 2002-02-02 08:34:02 Re: problem query ...