sqlite3 query by max and filter by second factor

前端 未结 3 1414
醉梦人生
醉梦人生 2021-01-27 01:01

I have:

TABLE MESSAGES
 message_id | conversation_id | from_user | timestamp  |  message

I want:

1. SELECT * WHERE from_user &l         


        
3条回答
  •  清酒与你
    2021-01-27 01:38

    ok it was more simple than I thought:

    basically to change select from:

    max(message_timestamp)
    

    to:

    max(message_timestamp || message_id)   
    or  max(message_timestamp + message_id) 
    

    so it will search for max on concatenation of timestamp and message_id

    ps. after a digging - it's working only if message id is growing with timestamp ( order of insertion is preserved )

    edit:

    edit2 :

    so why it works ?

    SELECT max(message_timestamp+message_id), message_timestamp, message_id, message_conversationId, message_from,message_text
    FROM MESSAGES
    WHERE message_conversationId = 1521521
    AND message_from <> 'me'
    ORDER by message_Timestamp DESC
    

提交回复
热议问题