Re: using LIMIT only on primary table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: dan(at)langille(dot)org
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: using LIMIT only on primary table
Date: 2002-03-02 23:22:35
Message-ID: 17340.1015111355@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice pgsql-sql

"Dan Langille" <dan(at)langille(dot)org> writes:
> If I want all the items on the last 100 orders, I'd start like this:

> SELECT *
> from orders, order_items
> where order_items.order_id = orders.id
> LIMIT 100

I think you want

SELECT *
from
(SELECT * from orders order by ID DESC limit 100) as recent_orders,
order_items
where order_items.order_id = recent_orders.id

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Dan Langille 2002-03-02 23:40:19 Re: using LIMIT only on primary table
Previous Message daq 2002-03-02 23:20:59 Re: [SQL] using LIMIT only on primary table

Browse pgsql-sql by date

  From Date Subject
Next Message Dan Langille 2002-03-02 23:40:19 Re: using LIMIT only on primary table
Previous Message daq 2002-03-02 23:20:59 Re: [SQL] using LIMIT only on primary table