MySQL query to return unique values in one column and sorted by id to get a PHP array -
i have following simplified table: (note skipped 2nd exam in exam_id
)
+----+---------+-------+ | id | exam_id | score | +----+---------+-------+ | 1 | 1 | 15 | | 2 | 1 | 20 | | 3 | 1 | 68 | | 4 | 3 | 92 | | 5 | 3 | 10 | +----+---------+-------+
i want write $sql
, php
(i'm using wordpress, , can use $wpdb
) able following:
$exam[3]=10 $exam[1]=68
not when there multiple exams, take score
entry corresponds largest id
, $exam[2]
empty. in words, i'd save last ever exam user attempted , show score.
i've tried using group ,
try this
select * exams exams.id in ( select max(id) exams group exam_id );
Comments
Post a Comment