Re: [SQL] Problem with limit / union / etc. - Mailing list pgsql-sql

From Alain.Tesio@sip.fr
Subject Re: [SQL] Problem with limit / union / etc.
Date
Msg-id C1256855.00659131.00@applications.sip.fr
Whole thread Raw
List pgsql-sql


--- "M. Scott Smith" <mssmit1@afterlife.ncsc.mil> wrote:
> select
>   event.title
> from
>   event, event_url, url
> where
>   date_start >= 'now'::date
>   and event.oid = event_url.eventid
>   and url.oid = event_url.urlid
>
> union
>
> select
>   event.title
> from
>   event,event_url
> where
>   date_start >= 'now'::date
>   and event.oid not in
>    (select distinct event_url.eventid from event_url)
>
> order by event.date_start asc limit $total;

Maybe the limit is applied only on the second query.

What about the following query ?

Alain

==

select event.title,date_start
into temp tmp_events
from event, event_url, url
where date_start >= 'now'::date and event.oid = event_url.eventid and url.oid = event_url.urlid
limit $total;

insert tmp_events
select event.title,date_start
from event,event_url
where date_start >= 'now'::date and event.oid not in  (select distinct event_url.eventid from event_url)
limit $total;

select title
from tmp_events
order by event.date_start asc limit $total;

drop table tmp_events;





pgsql-sql by date:

Previous
From: "M. Scott Smith"
Date:
Subject: Problem with limit / union / etc.
Next
From: Tom Lane
Date:
Subject: Re: [SQL] Problem with limit / union / etc.