I have asked this question Friday and since then I have been trying everything I could think of with no success
I cannot get this to work
SELECT * FROM WorldFlowers_table GROUP BY device_id ORDER BY score DESC LIMIT 100
and return me :
the 100 rows with the top 100 scores
filtered so that only the highest score of each device_id is featured
ORDER BY score DESC
@ 1000111 and Giorgos Betsos
A guy comes into a room, says, "please help, I'm getting crazy trying with all my forces to solve a simple problem that any of you could solve in the blink of an eye"
2 guys turn around, shoot the guy in the face and say "duplicate"
I am getting exhausted :(
///////// to adress Strawberry comment
I tried building that in SQLFiddle
CREATE TABLE WorldFlowers_table
(
id int identity primary key,
timestamp varchar(20),
name varchar(30),
score int,
color varchar(30),
flower varchar(30),
device_id varchar(30),
);
INSERT INTO WorldFlowers_table
(timestamp, name,score, color, flower, device_id )
VALUES
('1475151826', 'RI-RI', 42, '0|0|0|0|0|0|0|0|0|0', '[1475152768|42|4|0.0]', 'XYZ' ),
('1475151826', 'RO-RO', 46, '0|0|0|0|0|0|0|0|0|0', '[1475152768|42|4|0.0]', 'ABC' ),
('1475151826', 'RI-RI', 42, '0|0|0|0|0|0|0|0|0|0', '[1475152768|42|4|0.0]', 'XYZ' ),
('1475151826', 'RA-RA', 45, '0|0|0|0|0|0|0|0|0|0', '[1475152768|42|4|0.0]', 'ABC' ),
('1475151826', 'RU-RU', 42, '0|0|0|0|0|0|0|0|0|0', '[1475152768|42|4|0.0]', 'XYZ' ),
('1475151826', 'RE-RE', 44, '0|0|0|0|0|0|0|0|0|0', '[1475152768|42|4|0.0]', 'DEF' ),
('1475151826', 'RY-RY', 42, '0|0|0|0|0|0|0|0|0|0', '[1475152768|42|4|0.0]', 'XYZ' ),
('1475151826', 'RX-RX', 43, '0|0|0|0|0|0|0|0|0|0', '[1475152768|42|4|0.0]', 'XYZ' ),
('1475151826', 'RA-RA', 42, '0|0|0|0|0|0|0|0|0|0', '[1475152768|42|4|0.0]', 'DEF' );
but is does only builds one time out of 2.
The return I am looking for would then be
+------+------------+--------------------------------------------+
| id | timestamp | name | score | color | flower | device_id |
+------+------------+--------------------------------------------+
| 2 | blabla | RO-RO | 46 | ... | ... | ABC |
| 5 | blabla | RE-RE | 44 | ... | ... | DEF |
| 7 | blabla | RX-RX | 43 | ... | ... | XYZ |
+------+-------+-------------------------------------------------+
. only 1 of each device-id per return
. the highest score per device-id
. and the result being given in ORDER BY score DESC
UPDATE: this from scaisEdge seems to work fine
SELECT * FROM scores
WHERE (name, score) IN ( SELECT name, MAX(score)
FROM scores
GROUP BY name
ORDER BY score DESC
)
ORDER BY score DESC
LIMIT 100 ;