SQL Descending value incorrect












0















I am creating a dashboard project for a game and in my table the highscore is showing 900 however there are values that is higher than that, how is that possible.



here is the sample screenshot of my prototype web site
Sample Image Here



and here is the query I use
for high score to show



SELECT max( highscore ) as max FROM users


for the table



SELECT id,username, highscore FROM users ORDER BY highscore DESC


Here is the format of my table



Ranking || Highscore ||
1 || 945 ||
2 || 905 ||
3 || 823 ||
4 || 3457 ||
5 || 2680 ||


I want the highest value (3457) to be on the rank one but the 945 always goes to the top and the order is broken i hope the provided sample image helps I am really bad at explaining things online



thank you and sorry for the inconvenience










share|improve this question




















  • 4





    You are not giving us enough information to work with. My first thought I would think is that MAX is being used on strings by accident as 9 is higher than 2. Thats what my logic would state.

    – Fallenreaper
    Nov 18 '18 at 1:43













  • oh my bad i really am bad at explaining things online

    – Rolenz Pangan
    Nov 18 '18 at 1:51











  • run the sql statement desc users; and post output. (edit your question and add it, formatted, don't put it in a comment)

    – ivanivan
    Nov 18 '18 at 1:53











  • Show us your database schema.

    – Magnus Eriksson
    Nov 18 '18 at 1:58











  • Im sorry for the late reply I already edited my question im sorry again

    – Rolenz Pangan
    Nov 18 '18 at 2:12
















0















I am creating a dashboard project for a game and in my table the highscore is showing 900 however there are values that is higher than that, how is that possible.



here is the sample screenshot of my prototype web site
Sample Image Here



and here is the query I use
for high score to show



SELECT max( highscore ) as max FROM users


for the table



SELECT id,username, highscore FROM users ORDER BY highscore DESC


Here is the format of my table



Ranking || Highscore ||
1 || 945 ||
2 || 905 ||
3 || 823 ||
4 || 3457 ||
5 || 2680 ||


I want the highest value (3457) to be on the rank one but the 945 always goes to the top and the order is broken i hope the provided sample image helps I am really bad at explaining things online



thank you and sorry for the inconvenience










share|improve this question




















  • 4





    You are not giving us enough information to work with. My first thought I would think is that MAX is being used on strings by accident as 9 is higher than 2. Thats what my logic would state.

    – Fallenreaper
    Nov 18 '18 at 1:43













  • oh my bad i really am bad at explaining things online

    – Rolenz Pangan
    Nov 18 '18 at 1:51











  • run the sql statement desc users; and post output. (edit your question and add it, formatted, don't put it in a comment)

    – ivanivan
    Nov 18 '18 at 1:53











  • Show us your database schema.

    – Magnus Eriksson
    Nov 18 '18 at 1:58











  • Im sorry for the late reply I already edited my question im sorry again

    – Rolenz Pangan
    Nov 18 '18 at 2:12














0












0








0








I am creating a dashboard project for a game and in my table the highscore is showing 900 however there are values that is higher than that, how is that possible.



here is the sample screenshot of my prototype web site
Sample Image Here



and here is the query I use
for high score to show



SELECT max( highscore ) as max FROM users


for the table



SELECT id,username, highscore FROM users ORDER BY highscore DESC


Here is the format of my table



Ranking || Highscore ||
1 || 945 ||
2 || 905 ||
3 || 823 ||
4 || 3457 ||
5 || 2680 ||


I want the highest value (3457) to be on the rank one but the 945 always goes to the top and the order is broken i hope the provided sample image helps I am really bad at explaining things online



thank you and sorry for the inconvenience










share|improve this question
















I am creating a dashboard project for a game and in my table the highscore is showing 900 however there are values that is higher than that, how is that possible.



here is the sample screenshot of my prototype web site
Sample Image Here



and here is the query I use
for high score to show



SELECT max( highscore ) as max FROM users


for the table



SELECT id,username, highscore FROM users ORDER BY highscore DESC


Here is the format of my table



Ranking || Highscore ||
1 || 945 ||
2 || 905 ||
3 || 823 ||
4 || 3457 ||
5 || 2680 ||


I want the highest value (3457) to be on the rank one but the 945 always goes to the top and the order is broken i hope the provided sample image helps I am really bad at explaining things online



thank you and sorry for the inconvenience







php sql dashboard






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 2:09







Rolenz Pangan

















asked Nov 18 '18 at 1:38









Rolenz PanganRolenz Pangan

65




65








  • 4





    You are not giving us enough information to work with. My first thought I would think is that MAX is being used on strings by accident as 9 is higher than 2. Thats what my logic would state.

    – Fallenreaper
    Nov 18 '18 at 1:43













  • oh my bad i really am bad at explaining things online

    – Rolenz Pangan
    Nov 18 '18 at 1:51











  • run the sql statement desc users; and post output. (edit your question and add it, formatted, don't put it in a comment)

    – ivanivan
    Nov 18 '18 at 1:53











  • Show us your database schema.

    – Magnus Eriksson
    Nov 18 '18 at 1:58











  • Im sorry for the late reply I already edited my question im sorry again

    – Rolenz Pangan
    Nov 18 '18 at 2:12














  • 4





    You are not giving us enough information to work with. My first thought I would think is that MAX is being used on strings by accident as 9 is higher than 2. Thats what my logic would state.

    – Fallenreaper
    Nov 18 '18 at 1:43













  • oh my bad i really am bad at explaining things online

    – Rolenz Pangan
    Nov 18 '18 at 1:51











  • run the sql statement desc users; and post output. (edit your question and add it, formatted, don't put it in a comment)

    – ivanivan
    Nov 18 '18 at 1:53











  • Show us your database schema.

    – Magnus Eriksson
    Nov 18 '18 at 1:58











  • Im sorry for the late reply I already edited my question im sorry again

    – Rolenz Pangan
    Nov 18 '18 at 2:12








4




4





You are not giving us enough information to work with. My first thought I would think is that MAX is being used on strings by accident as 9 is higher than 2. Thats what my logic would state.

– Fallenreaper
Nov 18 '18 at 1:43







You are not giving us enough information to work with. My first thought I would think is that MAX is being used on strings by accident as 9 is higher than 2. Thats what my logic would state.

– Fallenreaper
Nov 18 '18 at 1:43















oh my bad i really am bad at explaining things online

– Rolenz Pangan
Nov 18 '18 at 1:51





oh my bad i really am bad at explaining things online

– Rolenz Pangan
Nov 18 '18 at 1:51













run the sql statement desc users; and post output. (edit your question and add it, formatted, don't put it in a comment)

– ivanivan
Nov 18 '18 at 1:53





run the sql statement desc users; and post output. (edit your question and add it, formatted, don't put it in a comment)

– ivanivan
Nov 18 '18 at 1:53













Show us your database schema.

– Magnus Eriksson
Nov 18 '18 at 1:58





Show us your database schema.

– Magnus Eriksson
Nov 18 '18 at 1:58













Im sorry for the late reply I already edited my question im sorry again

– Rolenz Pangan
Nov 18 '18 at 2:12





Im sorry for the late reply I already edited my question im sorry again

– Rolenz Pangan
Nov 18 '18 at 2:12












1 Answer
1






active

oldest

votes


















1














Maybe you declared the column Highscore like varchar? If you try this query:



SELECT id,
username,
highscore
FROM users
ORDER BY CAST(highscore as int) DESC


And



SELECT max( CAST(highscore as int) ) as max 
FROM users


What outputs if you cast it to integer?






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357170%2fsql-descending-value-incorrect%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Maybe you declared the column Highscore like varchar? If you try this query:



    SELECT id,
    username,
    highscore
    FROM users
    ORDER BY CAST(highscore as int) DESC


    And



    SELECT max( CAST(highscore as int) ) as max 
    FROM users


    What outputs if you cast it to integer?






    share|improve this answer






























      1














      Maybe you declared the column Highscore like varchar? If you try this query:



      SELECT id,
      username,
      highscore
      FROM users
      ORDER BY CAST(highscore as int) DESC


      And



      SELECT max( CAST(highscore as int) ) as max 
      FROM users


      What outputs if you cast it to integer?






      share|improve this answer




























        1












        1








        1







        Maybe you declared the column Highscore like varchar? If you try this query:



        SELECT id,
        username,
        highscore
        FROM users
        ORDER BY CAST(highscore as int) DESC


        And



        SELECT max( CAST(highscore as int) ) as max 
        FROM users


        What outputs if you cast it to integer?






        share|improve this answer















        Maybe you declared the column Highscore like varchar? If you try this query:



        SELECT id,
        username,
        highscore
        FROM users
        ORDER BY CAST(highscore as int) DESC


        And



        SELECT max( CAST(highscore as int) ) as max 
        FROM users


        What outputs if you cast it to integer?







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 6 '18 at 11:02

























        answered Nov 18 '18 at 3:23









        Nikasha Von carsteinNikasha Von carstein

        608




        608






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357170%2fsql-descending-value-incorrect%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()