Re: Combining single-key sorts to form concatenated-key sort
Date: Mon, 05 Feb 2001 07:54:45 +0100
Message-ID: <3A7E4E35.B601F7B6_at_elbanet.co.at>
Brian Inglis wrote:
>
> On 3 Feb 2001 06:51:48 -0000, Frog2
> <FrogRemailer_at_NoReply.Invalid> wrote:
>
> >I'm trying to sort some records. Each record consists of three data fields I wish to use
> >as a concatenated key for sorting purposes and some detail fields. All three key fields
> >are alphanumeric. All key fields in every record will always contain a value (no NULLs).
> >
> >Here's the problem: the language I'm using has a sort function but that function will
> >only let me sort on *one* field of my choice, not all three at once. So how can I achieve
> >a primary - secondary - tertiary sort of these records. Presumably there's some scalable
> >way to sort/merge each lower key with the key above it (or perhaps the reverse, sort from
> >primary key down to lowest-order key).
> >
> >What I've come with so far is make a list of each key field's unique values
> > unique_p , unique_s, unique_t
> >sorted in the order I want. But then how could I use these to extract the records in
> >correct overall sorted order?
> >
> >One subtlty - one or more key fields will contain only numbers. So if I try an "strcat-'em
> >all-together" solution I'll get bit by the "10-sorts-after-1-not-2" problem.
> >
> >Any ideas on how to do this? Please post any replies back to the list so that others may
> >learn.
>
> Sort by least significant key field, and so on up to most
> significant key field. Think about whay it works.
Maybe it doesn't work at all. It depends on the algorithm used for sorting since some algorithms don't preserve the order of equal elements.
Regards,
Heinz
Received on Mon Feb 05 2001 - 07:54:45 CET
