Good day!

From the table you need to get a list of fields: name , number and date , sorting by date, so that records with the most recent date go in descending order from top / down. But at the same time, it is necessary to exclude the repetition of records with the same name and number fields, and there will be a lot of similar ones.

Help to complete the query:

 $info = $this->db->table('table')->select('name', 'number', 'date')->where('hash', $hash)->orderBy('created_at', 'DESC')->distinct()->get()->toArray(); 

This request excludes repetitions of the same name and number , but also incorrectly sorts by the created_at field ...

    1 answer 1

    I advise you to try to group the values ​​by name then by number, thereby eliminating repetitions.

     $info = $this->db->table('table')->select('name', 'number', 'date') ->where('hash', $hash)->groupBy('name', 'number') ->orderBy('created_at', 'DESC')->get()->toArray(); 
    • What is mine is that your request correctly sorts only different users by date. I have duplicate users to check in the database with the same names and numbers, but different creation dates (created_at), so they are at the bottom of the list, even if their entries in the table are recent! Sorting does not work. - Valery Orlov
    • Although like the rules. Thank you - Valery Orlov
    • The sequence is important. If the problem is solved, check the box against the correct answer, so the question on this resource is closed. - Konstantin Soroka