0
$SQL->query('SELECT `p`.`name` AS  `name`,
  (SELECT `k`.`value` FROM `player_storage` k WHERE `k`.`key` = 1000  AND `k`.`player_id` = `p`.`id`) AS value
    FROM `player_storage` k, `players` p WHERE `k`.`player_id` = `p`.`id` GROUP BY  `name` ORDER BY CAST(`value` AS SIGNED) DESC LIMIT 0 , 30;

PLAYERS

id | name   
1    test

PLAYER_STORAGE

player_id | key | value 
1          1000   10

The query works fine the only is problem that the order is not correct, idk why.

Example: enter image description here

4
  • 4
    You are selecting two columns and output has only one column. Check your example Commented Feb 9, 2016 at 5:40
  • 1
    1. Why do not use a join instead of a subselect? 2. Are you sure that cast(value as signed) returns the value you expect and not just a bunch of zeros? Commented Feb 9, 2016 at 5:46
  • Another thing is there is a query, issued from php, and then there's this sort of html table rendering or whatever. Isn't there some intermediary post-processing stuff happening? Commented Feb 9, 2016 at 5:48
  • 1. Because i dont know what i'm doing, i have no knowledge in queries and i got this result just doing tests... the only problem is the order. 2. Yes, the original query works fine with cast(value as signed) Commented Feb 9, 2016 at 5:51

1 Answer 1

1

Your example will return two columns, you're only ordering the second column.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.