# Sorting cards

Alex Tweedly alex at tweedly.net
Thu Dec 30 10:25:33 EST 2021

```You shouldn't need to ignore the previous sort. The second sort
over-rides the first; it's only when looking at those cards which have
the same value for the second field that the previous sorting applies.

So if we have

A2 B1 A1 C3

If we sort by char 2 of each, we would get    B1 A1 A2 C3 (nb - all with
a 1, then all with a 2, ...)

and THEN sort by char 1 of each, we get   A1 A2 B1 C3 (all A then all B
then all ..., )

If we have A2 B1 A1 C3 and sort by char 1 of each, we get A2 A1 B1 C3
(all As before Bs, ...  and within the As they remain in the same order
as they were).

Hmmm - not sure if that's clear or not.

Other way to think of it : a stable sort means that items which have
matching keys remain in the same relative position.

Alex

(P.S. you're perhaps mixing up "first" and "second" - if want them
"properly" sorted, you do the less important one (minor) first, then the
major one. Hope that doesn't muddy it any more.)

On 30/12/2021 06:41, J. Landman Gay via use-livecode wrote:
> I am converting an old stack to LC and it needs to sort cards by one
> of two fields. LC does stable sorts, so if I sort by field 1 it works,
> and then if I sort later by field 2 it retains the original sort and
> does a sub-sort. I don't want that. What's the best way to ignore the
> previous sort order?
>
> I've tried a number of things with no luck.
>

```