SELECT DISTINCT

SELECT DISTINCT

belubelu Posts: 38Questions: 14Answers: 0

Hi,
I have a table with messages sent to users. Many of the messages are the same with the only difference, that they have been sent to other user_ids. Messges that are the same have the the same message_group_id. So I would like to show only messages with different message_group_ids in the table. Is there a way to do something like "SELECT DISTINCT" in editor?

Thanks!

Answers

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin

    I'm afraid there isn't, because if you attempted to edit a row, they must already be distinct, otherwise multiple rows might be edited. Normally the primary key is the field that makes them distinct.

    Do you want to have them as editable, or just view only here?

    Allan

  • belubelu Posts: 38Questions: 14Answers: 0

    ok - that makes sense...
    It would be fine to have it for view only...

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    @belu wrote: "It would be fine to have it for view only..."

    Here is how I did SELECT DISTINCT with PHP and the Editor "postGet" Event:

    ->on( 'postGet', function ( $e, &$data, $id ){ 
       $data = array_values(array_unique($data, SORT_REGULAR));
    })
    

    make sure you use &$data so that it gets passed by reference and can be manipulated. Just passing $data won't work because you would only be manipulating a copy of the data returned to the client.

This discussion has been closed.