Split and search for older and newer messages

4

I have a table . In it to 4 columns
ID with high increment,
id_user1 would be the id of the user who sent the message,
id_user2 would be the id of the user that received and the mensagem to which it receives the message sent by id_user1 to id_user2 .

Is there any way to fetch the latest ones for a message list? I mean, we have the Whatsapp and several other applications that follow the same system as the message list, where they go up according to the latest one.

I know what to do with a DESC , but I wanted something dynamic that shows up in real time and is separated by ide like the applications and not the ID 1 now and then the ID 1 again in the 4 or 5 and etc ... each separated and without showing the same id_user1 again ..

Do you understand?

    
asked by anonymous 15.07.2015 / 14:48

1 answer

1

By adding a column to your table, you can sort at will using SELECT , without even touching every record in the table. For example:

ALTER TABLE tabela ADD data_enviada DATETIME;

Then, I could write a query like this:

SELECT
   ID,
   id_user1,
   id_user2,
   id_mensagem
FROM
   tabela
ORDER BY
  data_enviada

This is sorted by date, but not necessarily showing the date.

    
17.07.2015 / 23:11