Re: using LIMIT only on primary table - Mailing list pgsql-sql

From Tom Lane
Subject Re: using LIMIT only on primary table
Date
Msg-id 17340.1015111355@sss.pgh.pa.us
Whole thread Raw
In response to using LIMIT only on primary table  ("Dan Langille" <dan@langille.org>)
Responses Re: using LIMIT only on primary table  ("Dan Langille" <dan@langille.org>)
List pgsql-sql
"Dan Langille" <dan@langille.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


pgsql-sql by date:

Previous
From: "Dan Langille"
Date:
Subject: using LIMIT only on primary table
Next
From: "Dan Langille"
Date:
Subject: Re: using LIMIT only on primary table