Thread: select distinct and order by

select distinct and order by

From
newsreader@mediaone.net
Date:
Pg complained that select distinct column and
order by column must be the same.

Is there any way to get around that?

If not I have some questions re DBI

Say I am using perl DBI to retrieve
like
------------
$s=$dbd->prepare('select ...');
$s->execute(...);

while(my @a=$s->fetctrow_array())
    {
    .
    .
    .
    }
---------------

And let's say select statement return 10,000
records and I exit the loop after reading
1000 records.  Let's also say that
the client and server are on different
boxes.  Is 10,000 records transferred
over the network even if I quit after
reading 1000 records?

Thanks in advance



Re: select distinct and order by

From
Stephan Szabo
Date:
On Thu, 16 Aug 2001 newsreader@mediaone.net wrote:

> Pg complained that select distinct column and
> order by column must be the same.

Depending on what you are doing, you may be able to
use group by with an explicit set value function on
the sort by field (for example:
select foo from table group by foo order by min(bar);)

(I don't know anything about the dbi interface really, so i'll
leave that part for someone who does)



Re: select distinct and order by

From
newsreader@mediaone.net
Date:
Thanks.  I don't know much about grouping but
I will now study that thing

On Wed, Aug 15, 2001 at 10:56:33PM -0700, Stephan Szabo wrote:
>
> On Thu, 16 Aug 2001 newsreader@mediaone.net wrote:
>
> > Pg complained that select distinct column and
> > order by column must be the same.
>
> Depending on what you are doing, you may be able to
> use group by with an explicit set value function on
> the sort by field (for example:
> select foo from table group by foo order by min(bar);)
>
> (I don't know anything about the dbi interface really, so i'll
> leave that part for someone who does)
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org