Wrong Result
#1

Код:
SELECT `playerName`,`playerScore` FROM `playerdata` where `playerScore` > 100 order by `playerScore` desc LIMIT 0,10
if i have to use this,it will sort wrong

it not goes the higher to lower
but,result will look like this
we will use example player name for this


Cody 991
Bust 987
Mstr 967
... and etc.

and thats not a highest score on the database,the higher score is 20000
Reply
#2

Something's probably wrong with your database, This query works should work, I don't understand why do you use "LIMIT 0,10" and not just 10 though ?
Reply
#3

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
I don't understand why do you use "LIMIT 0,10" and not just 10 though ?
That means: start from the 0th row and select the next 10, so shouldn't make a difference.

As for the problem: this is likely caused by the column being declared as a text type rather than an integer type, in which case the column will be sorted alphabetically (z-a and also 9-0) rather than numerically.
Reply
#4

Bump..
Reply
#5

Vince already gave a possible issue.

Quote:
Originally Posted by Vince
Посмотреть сообщение
this is likely caused by the column being declared as a text type rather than an integer type, in which case the column will be sorted alphabetically (z-a and also 9-0) rather than numerically.
Are you sure you're using numeric values and not any type of strings for the column "playerScore"'s type ?
Reply
#6

Yep.
Reply
#7

Either convert the Column type to an integer type(this option is better in my opinion)
Or
Use this query
PHP код:
SELECT playerName,playerScore FROM playerdata where CONVERT(playerscoreSIGNED INTEGER) > 100 order by ORDER BY CONVERT(playerscoreSIGNED INTEGERdesc LIMIT 10 
You can avoid using `` around column names as long as it is not an MySQL reserved keyword or as long as the column name doesn't have any space in its name.
And also LIMIT 0,10 is same as LIMIT 10 so use LIMIT 10 as it will make query smaller.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)