mercredi 30 septembre 2015

sqlite query with second joining

i have table MESSAGES :

enter image description here

holding messages from users conversations

each conversation looks like this:

enter image description here

now i have query which returns me a list of last message ( *last is defined as max timestamps / max message id ) from each conversation

enter image description here

every row in MESSAGES TABLE holds info about one side of conversation who sends message eg. me or other person

when i QUERY I for all conversations i need to know second side of conversation so i need to add to this QUERY II a select / join statement

LEFT JOIN 
 (  SELECT message_conversationId, message_from as message_from2, message_avatar_pic_id as message_avatar_pic_id_from2
    FROM Messages  msg_from
    WHERE message_from <> 'me' COLLATE NOCASE 
    AND user_id == 1
    GROUP BY message_conversationId
  ) not_me ON message_conversationId = not_me.message_conversationId

to have this result:

enter image description here

How to combine those two queries I + II ?

Aucun commentaire:

Enregistrer un commentaire