i have this query, which works fine
SELECT count(*) cnt, b.message_lot_num,
t.name AS trigger_name, tm.name AS template_name
FROM messages b
LEFT JOIN triggers t ON t.trigger_id = b.trigger_id
LEFT JOIN templates tm ON tm.template_id = t.template_id
WHERE b.account_id = $1
AND sms_direction = 'out'
GROUP BY message_lot_num, t.name, tm.name
ORDER BY message_lot_num DESC LIMIT $2
What i would like to do is return the top record for each group by.
each of these groups message_lot_num shares the same message(but is just a little different because of the recpt name, so i can not add that in the group by). So i am trying to get a sample message to display with that group
is that possible?
thanks for any help