0

I need to get the last group of my data. I already did order_by but still it did not produce my expected output

For visual reference here is what my table and its value are

enter image description here

So I need to get the last group of data, where in the Capital of Australias is repeated in id number 5 .

Here is my Model and my query.

public function view_results($id){
    $this->db->select('*');
    $this->db->from('results');
    $this->db->where('post_id', $id);
    $this->db->order_by('date_answered', 'DESC');
    $this->db->group_by('question');    
    $query = $this->db->get();
    return $result = $query->result_array();
}
  • What do you mean by "last group"? Can you add the expected result to your question? – El_Vanja Mar 25 '20 at 02:23
  • @El_Vanja - I group by the question and I am expecting to get the ids `5` to `8` which is the last group of the test. – Madara Code Mar 25 '20 at 02:24
  • @El_Vanja - As you know, I am only getting ids `1` to `4` which is the first group of the data. – Madara Code Mar 25 '20 at 02:25
  • [This answer](https://stackoverflow.com/a/35456144/4205384) should help. – El_Vanja Mar 25 '20 at 02:44
  • @El_Vanja hello sir, can you kindly help me with the syntax? and the rest is for myself. just needed to get out of this problem please. thank you! – Madara Code Mar 25 '20 at 02:54
  • that's a very odd way to write a SQL statement... Please display the SQL statement as we don't know how you put the pieces together. Also, make clear what you mean by "the last group of my data" – Manny Ramirez Mar 25 '20 at 05:39
  • @MannyRamirez He wants the latest answer for each question. Madara, can you please edit the question so we can see how you tried to create the subquery? – El_Vanja Mar 25 '20 at 10:12

0 Answers0