X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 56B0C475BA1 for ; Wed, 12 Feb 2003 15:25:39 -0500 (EST) Received: from exchange.hq.openratings.com (unknown [141.149.165.226]) by postgresql.org (Postfix) with ESMTP id 6F052475B8A for ; Wed, 12 Feb 2003 15:25:38 -0500 (EST) Received: from openratings.com (cancun.hq.openratings.com [10.0.0.225]) by exchange.hq.openratings.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id DQJTWNPC; Wed, 12 Feb 2003 15:25:39 -0500 Message-ID: <3E4AC4E1.3040700@openratings.com> Date: Wed, 12 Feb 2003 17:04:17 -0500 From: Dmitry Tkach User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Nicholas Allen Cc: pgsql-sql@postgresql.org Subject: Re: How do you select from a table until a condition is met? References: <200302121910.38232.nallen@freenet.co.uk> <200302122010.15297.nallen@freenet.co.uk> <3E4AB5C4.4040105@openratings.com> <200302122100.11398.nallen@freenet.co.uk> In-Reply-To: <200302122100.11398.nallen@freenet.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/258 X-Sequence-Number: 11656 > > >No. What I'm saying is the user scrolls through a list then selects an item. >They then decide to sort on something else but they still want the item they >selected to be selected after the sort has completed. So I need some way to >work out where the previously selected item will be in the new sort order so >I can scroll to that position and select it again. > >eg If user selects "John Doe" when sorted by First name and then decides to >sort by Surname I still want John Doe selected and the user should be able to >see the record. > > What do you mean by 'select the item'? Get all the rows before it? This still doesn't make much sense to me - you said before, that the whole purpose of your 'browser' was to avoid sending tons of data to the client side, but if I understand correctly what you are thinking about doing, it won't work, because you do not know how many rows are before the 'selected' item. Am I still missing something? Anyway, what about this: select * from people order by last_name, id limit 100; -- get first 100, ordered by the last_name select * from people where first_name < 'John' or first_name = 'John' and last_name <= 'Doe' and id <= "JohnDoe's ID" order by first_name, id; -- get everything before the last seen John Doe ordered by the first name select * from people where first_name > 'John' or first_name = 'John' and last_name >= 'Doe' and id >= "JohDoe's ID" order by first_name, id limit 100; -- get 100 rows after the selected one sorted by first name etc... Still can't imagine how this can be useful though :-( Dima