Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 69558 invoked from network); 17 Feb 2006 15:57:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Feb 2006 15:57:39 -0000 Received: (qmail 4604 invoked by uid 500); 17 Feb 2006 15:57:29 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 4528 invoked by uid 500); 17 Feb 2006 15:57:29 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 4477 invoked by uid 99); 17 Feb 2006 15:57:29 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Feb 2006 07:57:28 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [65.195.181.55] (HELO dbrack01.segel.com) (65.195.181.55) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Feb 2006 07:57:24 -0800 Received: from dbrack01.segel.com (dbrack01.segel.com [65.195.181.55]) by dbrack01.segel.com (Postfix - We shoot spammers on site.) with ESMTP id DAA1F159EC for ; Fri, 17 Feb 2006 09:59:06 -0600 (CST) From: Michael Segel Reply-To: derby@segel.com Organization: MSCC To: "Derby Discussion" Subject: Re: Using/Adressing a "row number" in a SELECT query Date: Fri, 17 Feb 2006 09:59:06 -0600 User-Agent: KMail/1.8.2 References: <334d65b80602162347m6836e8c8uf0874aebd89f4697@mail.gmail.com> In-Reply-To: <334d65b80602162347m6836e8c8uf0874aebd89f4697@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200602170959.06529.derby@segel.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On Friday 17 February 2006 1:47 am, Sylvain RICHET wrote: > Hi everyone, > > In a selection statement, i would like to get blocks of records. > Thus, i need to filter records by a "row number", directly at the SELECT > level. > Hmmm, not sure this is going to give you the results that you want. You're implying that you want to select a record and its rowId. Then grab the first n row by using the rowId then fetch the next n rows at a later time again using rowId. > It seems that the way to address a row number is not (SQL) standard. > (different "proprietary" implementations) > Yup. The rowId really isn't part of the result set. Its more of some meta data if anything. Its also misleading and shouldn't be used anymore. (Unless you have a very good reason ... like writing your own index or something... ;-) > In Oracle, there is the "rowid". > In MySQL, the "LIMIT" clause can do it. > In SQL Server, i think there is the "ROW_NUMBER() OVER..." > In DB2 (on AS/400) , there is the "RRN" (Relative Record Number)... > Right. And Informix has a rowId, however when you start to partion the DB tables, the rowId is no longer unique. Again, for what you want, rowId is not going to work.... Imagine you have a table. You do a select on the table and you select rows 1, 5, 10, 11,13,17 ... How does this help you when you want to fetch the first n rows? I think you need to go back and rethink your design. Based on your initial problem statement, rowId is not the best or even a good way of handling this. Did you ever consider using a couple of prepare statements and scrolling cursors? ;-) (And if necessary a temp table...) But hey, what do I know? I was a quasi-sales critter for the last 4 years... don't take my word for it. Take a fifth of scotch, and think about the problem you're trying to solve. You'll get it eventually. ;-) -- -- Michael Segel Principal Michael Segel Consulting Corp. derby@segel.com (312) 952-8175 [mobile]