Results 1 to 4 of 4

Thread: How to sort a multi-column data?

  1. #1

    Thread Starter
    Fanatic Member sbasak's Avatar
    Join Date
    Aug 2001
    Location
    Globe Trotter
    Posts
    524

    How to sort a multi-column data?

    How to sort a multi-column data? That is, suppose an array contains following columns

    LastName
    FirstName
    Country
    City

    I want to sort them by LastName, FirstName, Country, City.

    What is the way to that? One obvious solution appears to concatenate each field value as a single string and sort then, but is there any better solution? Also, if any field is number, the above said method won't work easily? Any suggestion?

    Please don't post database commands (like order by). I like to know how to do it programmatically.

    thanks
    Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
    Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Sounds a little like a recursive loop, but perhaps worse.

    One way
    First you need to compare on the first field - for the whole array
    Then you need to compare the second field ONLY if the first fields match.
    Then you need to compare the third field ONLY if the second nad first fields match
    ...And so on...

    Whether you can do this in one loop or several is up to you.

    I think (personally) that it has to be several - so the array is sorted properly, but this may hit your processing time.


    I'd be interested in your results, if you record times and come up with a way in one loop and a way using several loops to which is faster and produces the correct results. Post up wen you've done it.

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Fanatic Member sbasak's Avatar
    Join Date
    Aug 2001
    Location
    Globe Trotter
    Posts
    524
    Thanks for suggestion. Can you tell me how does the databases (Oracle, SQL Server etc.) implement this kind of sort?
    Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
    Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    India
    Posts
    342

    if ur using ADO recordsets then...

    I want to sort them by LastName, FirstName, Country, City
    if u get that record in ADO recordset 'Rs' then u can sort on multiple fields ..
    VB Code:
    1. rs.sort="LastName, FirstName, Country, City"
    ksm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width