pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: dan@langille.org
Cc: pgsql-sql@postgresql.org
Subject: Re: using LIMIT only on primary table
Date: Sat, 02 Mar 2002 18:22:35 -0500
Message-ID: <17340.1015111355@sss.pgh.pa.us> (raw)
In-Reply-To: <200203022235.g22MZYk55756@lists.unixathome.org>
References: <200203022235.g22MZYk55756@lists.unixathome.org>

"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



view thread (7+ messages)  latest in thread

Message-ID: <17340.1015111355@sss.pgh.pa.us>
Permalink:  ../17340.1015111355@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17340.1015111355@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dan@langille.org
  Subject: Re: using LIMIT only on primary table
  In-Reply-To: <17340.1015111355@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox