mercredi 25 mars 2015

GROUP BY parentId and MAX childId


My tables are below:


crm_conversions


crm_conversions crm_messages_of_conversions crm_messages_of_conversions

crm_receivers_of_messages crm_receivers_of_messages I want to get all of conversions of an user with only last message. I'm trying to get with the query:



SELECT `conv`.`subject`, `mc`.`message_text`, `mc`.`sentDateTime`, `mc`.id AS "msgId", `conv`.id AS "convId"
FROM (`crm_receivers_of_messages` rm)
JOIN `crm_messages_of_conversions` mc ON `mc`.`id` = `rm`.`m_id`
JOIN `crm_conversions` conv ON `conv`.`id` = `mc`.`conv_id`
WHERE `rm`.`receiver_id` = '1'
GROUP BY convId
HAVING MAX(msgId)


But that query does not to give me true result: result I wanna to get msgId = 1 of convId 1, msgId = 4 of convId = 2





Aucun commentaire:

Enregistrer un commentaire