Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    Stockholm, Sweden
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sort by more than one field in SQL?

    Hi,

    I wonder if it is possible to sort after more than one
    field in SQL?

    example: now it looks like this

    Code:
    rs.open "select * from [guld7i5] order by [POINTS] desc", conn
    this works just fine but in the end of my table there is
    2 players that have the same points and they happens
    to be in the wrong order if I look on the position

    so I tried this (which didn't work ofcourse)

    Code:
    rs.open "select * from [guld7i5] order by [POINTS] desc then order by [POS] asc", conn
    So my question is if there is any way of doing this?

    /Speedy

  • #2
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mmh... the right syntax of your sql request would be
    Code:
    rs.open "select * from [guld7i5] order by [POINTS] desc, [POS] asc", conn
    But I'm not sure that it will do what you want since it might just reverse the pos related to the points...

    this link might help you anyways:

    http://www.w3schools.com/sql/sql_orderby.asp

  • #3
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just would like to add something... an advice... it's a good coding practice to name your recordsets, like: rsShowResults... and it's a good idea to write your sql statement out of your rs, and then make the rs open it. Like this:
    Code:
    sql= ""select * "
    sql= sql & "from [guld7i5]"
    sql= sql &  "order by [POINTS] desc"
    ...etc...
    rsShowResults=server....
    rsShowResults.open sql, conn
    it might not be helpfull for simple data retrieval but if you come to have a much longer and complicated code it will just be better for you to have already your code like that... It will also make debuging easier and the use of "if" statements inside a request much easier..
    Last edited by jeskel; 11-08-2003 at 02:04 PM.

  • #4
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I realize that this is a very old thread, but I got here while searching for the answer to this question, and thought that other folks might be looking for answers here as well. To sort by two fields try

    rs.open "select * from [guld7i5] order by [POINTS] desc, [POS] asc", conn

    I found this at

    http://www.sql-tutorial.com/sql-order-by-sql-tutorial/


  •  

    Posting Permissions

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