dcsimg
Results 1 to 7 of 7

Thread: Order By

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,268

    Order By

    Hi to all,

    I have this query:

    Code:
     sql = _
          "select primeira_prova_pontos, segunda_prova_pontos " & _
          " from tabela_resultados_geral " & _
          " order by primeira_prova_pontos desc, segunda_prova_pontos desc "
    and the sort as this:

    Name:  Sort.jpg
Views: 58
Size:  39.4 KB

    The second collumn is not order by desc....something wrong in sql code?

    Thanks

  2. #2
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    323

    Re: Order By

    You are sorting by two columns. The second column is sorted in descending order for rows that have the same value in the first column, and everything looks correct. For your rows where the first column is 16 or 0 the values in the second column are correctly sorted in descending order. The other rows appear to have distinct values in the first column.

    If you are expecting that both columns will be completely sorted in descending order from top to bottom, that's not what is going to happen.

  3. #3
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    323

    Re: Order By

    If you want it to be sorted by the second column you need to remove "order by primeira_prova_pontos desc," from your query, but then it will not be sorted by the first column.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,813

    Re: Order By

    The second column is ordered descending, but only after the ordering of the first column.

    If you look at the first column and find the repeated values (16 and 0) you will see that the values in the second column are ordered descending (19,0 and 20,13,12).

    As both values come from the same row of data, it wouldn't really make much sense for it to be any other way. If you want a different output then explain (with an example) what you want.


    edit: I was slow!

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,268

    Re: Order By

    Hi,

    Yes guys you are right...the sort are correct!
    I need to chance the query

    Thanks

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,682

    Re: Order By

    Quote Originally Posted by sacramento View Post
    I need to chance the query
    Presumably you mean "change" rather than "chance". Why do you need to change the query? What are you trying to achieve that the query is not already achieving? If you expect both columns to be sorted independently then I don't see how that makes sense. It could be done but it would take a few intermediate steps. It's not something that can be done easily because it's not something that people generally want to do.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,268

    Re: Order By

    Hi jmcilhinney,

    In fact i need to make others steps to sort that i want.

    Thanks for your help

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.