Re: VIEW / ORDER BY + UNION

From: CoL <col(at)mportal(dot)hu>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: VIEW / ORDER BY + UNION
Date: 2005-02-18 08:26:26
Message-ID: cv48la$m4p$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

hi,

WeiShang wrote, On 2/17/2005 16:46:
> Hi, I have created a view like this :
>
> CREATE VIEW v1 AS (SELECT orderno,weekday,time FROM t1,t2 where
> t1.orderno=t2.orderno);
>
> if I create a SQL statment:
>
> (SELECT orderno FROM v1 WHERE weekday='MON' ORDER BY orderno)
> UNION
> (SELECT orderno FROM v1 WHERE weekday='WED' ORDER BY orderno)
> UNION
> (SELECT orderno FROM v1 WHERE weekday='FRI' ORDER BY orderno);
>
> Will the whole result will be sorted by the field orderno?

nothing says it will. you havet to sort the set of unions.
(select orderno ) union (select orderno ) order by orderno.

Not necessary now (no sense), to use order by in selects inside union.

C.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 2005-02-18 11:00:52 Re: No triggers visible for different user in information_schema.triggers
Previous Message Iain 2005-02-18 06:34:43 Re: pg primary key bug?