Re: ERROR: for SELECT DISTINCT, ORDER BY expressions must - Mailing list pgsql-general

From Bricklen Anderson
Subject Re: ERROR: for SELECT DISTINCT, ORDER BY expressions must
Date
Msg-id 448880E4.4020304@presinet.com
Whole thread Raw
In response to ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list  ("sergey kapustin" <master.sergey@gmail.com>)
List pgsql-general
sergey kapustin wrote:
> Hi all!
> can anybody say me what's wrong with this query. I just try to take
> unique values from table column and print them in random order
>
> select distinct num from (select 1 as num union select 2 as num union
> select 1 as num union select 3) t order by random();
> ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select
> list
>
> thank you


select num from
     (select distinct num
     from (select 1 as num union select 2 as num union select 1 as num
union select 3 as num) a) t
order by random();

pgsql-general by date:

Previous
From: "Harry Hehl"
Date:
Subject:
Next
From: Tom Lane
Date:
Subject: Re: SessionID, pretty please