Re: find position of row in set of rows
Date: Fri, 29 Jan 2010 18:01:18 +0100
On 29.01.2010 04:00, Mladen Gogala wrote:
> On Thu, 28 Jan 2010 10:49:56 -0800, cate wrote:
>> I have a table ordered by date. When I find a specific record in this
>> set, I want to know what its position is in this ordered list.
>> I could get the date from the record found and count dates above or
>> below, but is there a better way?
>> Thank you.
> Wrong paradigm. Ordered lists are from another story. Relational
> databases are modeled after naive set theory and deal with subsets.
> Relational databases do not deal with Abelian groups, Lie algebras,
> vector spaces or ordered lists, they deal with subsets. Subsets are,
> generally speaking not ordered, although any set can be well ordered,
> provided we accept so called Zermelo's axiom of choice, but that's no
> longer the naive set theory. If you need a database to return you an
> ordered list, you are having an application design issue.
I don't fully agree: certainly relational DB and SQL started out at relational algebra, but there are significant features (even in standard SQL) that are not really covered by set theory (just to name ORDER BY and the Oracle specific CONNECT BY).
I do agree if OP wants to remember the position for some later access. That's not a good idea. But it can be reasonable to have the DB return positional numbers so you can easily print them in some form of UI or report.
-- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/Received on Fri Jan 29 2010 - 11:01:18 CST