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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -