View Full Version : sort by more than one field in SQL?

11-08-2003, 12:21 PM

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

example: now it looks like this

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)

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?


11-08-2003, 01:28 PM
mmh... the right syntax of your sql request would be

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:


11-08-2003, 01:35 PM
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:

sql= ""select * "
sql= sql & "from [guld7i5]"
sql= sql & "order by [POINTS] desc"
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..

10-04-2010, 10:19 PM

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