Re: Selecting from two unrelated tables

From: Bricklen Anderson <banderson(at)presinet(dot)com>
To: CSN <cool_screen_name90001(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting from two unrelated tables
Date: 2006-09-20 19:57:28
Message-ID: 45119D28.3080401@presinet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

CSN wrote:
> I have two tables:
>
> items: id, title, added, ...
> news: id, headline, datetime, ...
>
> I'd like to select the latest 25 combined records from both tables. Is there a way to do this
> using just select?
>
> Thanks,
> csn
>

Maybe something like this?

select id,title_headline,dt
from (
select id,title as title_headline,added as dt from ...
union all
select id,headline as title_headline,datetime as dt from ...) as a
order by dt limit 25;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John Sidney-Woollett 2006-09-20 20:00:33 Re: Selecting from two unrelated tables
Previous Message CSN 2006-09-20 19:49:00 Selecting from two unrelated tables