I need help with mysql query.
So, I have table like this
---------------------------------------------------------------
ReceivingDateTime | SenderNumber | TextDecoded | UDH |
---------------------------------------------------------------
2013-01-31 16:12:19 | +70000001111 | Bla-bla-bla | 050003A70201 |
2013-01-31 16:12:19 | +70000001111 | Bla-bla-bla | 050003A70202 |
2012-01-20 19:24:21 | +70000001111 | Bla-bla-bla | |
2012-01-18 14:14:19 | +70000002222 | Bla-bla-bla | |
2012-01-21 13:12:20 | +70000002222 | Bla-bla-bla | |
2012-01-15 17:12:10 | +70000003333 | Bla-bla-bla | 050003DC0201 |
2012-01-15 17:13:18 | +70000003333 | Bla-bla-bla | 050003DC0202 |
And now my query is
SELECT
GROUP_CONCAT(TextDecoded SEPARATOR '') TextDecoded,
`ID`
FROM `inbox`
GROUP BY IF(UDH='',id,SUBSTR(UDH,1,10)) ORDER by `ReceivingDateTime` DESC;
Question
It works almost fine, but I wanna see something like this
-------------------------------------------------------------
ReceivingDateTime | SenderNumber | TextDecoded |
-------------------------------------------------------------
2013-01-31 16:12:19 | +70000001111 | Bla-bla-blaBla-bla-bla |
2012-01-21 13:12:20 | +70000002222 | Bla-bla-bla |
2012-01-15 17:12:10 | +70000003333 | Bla-bla-blaBla-bla-bla |
How I think it should work: Group TextDecoded by UDH, sort by Date, keep only unique SenderNumber which newer than other same SenderNumber. (maybe it's wrong). Sorry for my French.