There is a table with messages.

How to make a request so that it returns only those messages that did not receive a response.

That is, there is a table

id|dialog|is_read|mess - это примерная таблица для наглядности 1 |1 |0 |265 2 |1 |1 |ыва 3 |1 |0 |ваи 4 |1 |0 |123 

In the table there is a ts field (unix timestamp);

It is necessary to return the last two lines, because the line with id = 1 has already received the answer (id = 2), it’s just that the read mark didn’t have time to go to the server and change.

The dialog field is not a constant; it is a dialog id.

This question is related to this. Instant messages: reading messages - so that it is clear.

    1 answer 1

     select * from `your_table` where `dialog`=$dialog and (`id`>(select max(`id`) from `your_table` where `is_read`=1 and `dialog`=$dialog) or (select count(*) from `your_table` where `is_read`=1 and `dialog`=$dialog)=0) 

    I advise you to think over the structure of the database.

    • Problem found: if one message is sent, the request returns 0. - Oleg
    • The problem is urgent! - Oleg
    • Updated the answer. - KaZaca