SQL Descending value incorrect
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
|
show 1 more comment
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
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 statementdesc 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
|
show 1 more comment
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
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
php sql dashboard
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 statementdesc 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
|
show 1 more comment
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 statementdesc 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
|
show 1 more comment
1 Answer
1
active
oldest
votes
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?
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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?
add a comment |
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?
add a comment |
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?
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?
edited Dec 6 '18 at 11:02
answered Nov 18 '18 at 3:23
Nikasha Von carsteinNikasha Von carstein
608
608
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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