Private messaging system. Listing last message of each conversation

前端 未结 3 1423
梦如初夏
梦如初夏 2021-02-15 17:58

Lets say this is the database structure:

\"enter

SELECT * FROM `pms` where         


        
3条回答
  •  独厮守ぢ
    2021-02-15 18:45

    select pms.* from pms 
    inner join 
        (select max(fecha) as max_fecha,
               if(id_to

    Also if id_to and id_from in your table are small enough to prevent overflow in statement (id_to+id_from) here is the simple query:

    select pms.* from pms 
    inner join 
        (select max(fecha) as max_fecha, id_to+id_from as sum_id
          from pms where id_to = 1 or id_from = 1 
             group by id_to+id_from) t 
         on ((pms.id_to+pms.id_from)=t.sum_id) 
            and (pms.fecha=t.max_fecha)
     where pms.id_to = 1 or pms.id_from = 1
    

提交回复
热议问题