pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Masaru Sugawara <rk73@sea.plala.or.jp>
To: dan@langille.org
Cc: pgsql-sql@postgresql.org
Subject: Re: using LIMIT only on primary table
Date: Sun, 03 Mar 2002 15:00:01 +0900
Message-ID: <20020303141057.614C.RK73@sea.plala.or.jp> (raw)
In-Reply-To: <200203022235.g22MZYk55756@lists.unixathome.org>
References: <200203022235.g22MZYk55756@lists.unixathome.org>

On Sat, 2 Mar 2002 17:35:31 -0500
"Dan Langille" <dan@langille.org> wrote:

> If I want the last 100 orders:
> 
> SELECT * FROM orders LIMIT 100;
> 
> 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
> 
> But that will only give me the last 100 items, not 100 orders.
> 
> What I really want is 
> 
> SELECT * 
> from orders, order_items 
> where order_items.order_id = orders.id
> and exists
> (SELECT * from orders order by ID DESC limit 100);


This probably gives you all the items on the last 100 orders.

 select * 
  from (select * from orders order by ID desc limit 10) as o
       inner join order_items as oi
        on (oi.order_id = o.order_id)
;


> 
> But that gives me all orders, not just the first 100.
> 
> Adding a LIMIT 100 to the above doesn't work either.  It equates to the 
> first example.



Regards,
Masaru Sugawara





view thread (7+ messages)  latest in thread

Message-ID: <20020303141057.614C.RK73@sea.plala.or.jp>
Permalink:  ../20020303141057.614C.RK73@sea.plala.or.jp/
Also on:    postgresql.org/message-id/20020303141057.614C.RK73@sea.plala.or.jp

 · 

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: rk73@sea.plala.or.jp, dan@langille.org
  Subject: Re: using LIMIT only on primary table
  In-Reply-To: <20020303141057.614C.RK73@sea.plala.or.jp>

* 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