Received: from lists.unixathome.org (lists.unixathome.org [210.48.103.158]) by postgresql.org (Postfix) with ESMTP id 6B2CC4759BD for ; Sat, 2 Mar 2002 17:35:34 -0500 (EST) Received: from wocker (lists.unixathome.org [210.48.103.158]) by lists.unixathome.org (8.11.6/8.11.6) with ESMTP id g22MZYk55756 for ; Sun, 3 Mar 2002 11:35:34 +1300 (NZDT) (envelope-from dan@lists.unixathome.org) Message-Id: <200203022235.g22MZYk55756@lists.unixathome.org> From: "Dan Langille" Organization: DVL Software Limited To: pgsql-sql@postgresql.org Date: Sat, 2 Mar 2002 17:35:31 -0500 MIME-Version: 1.0 Subject: using LIMIT only on primary table Reply-To: dan@langille.org X-mailer: Pegasus Mail for Windows (v4.01) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200203/19 X-Sequence-Number: 6901 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); 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. Clues? cheers -- Dan Langille The FreeBSD Diary - http://freebsddiary.org/ - practical examples