Here is my table:
+----+---------+------------+----------+
| id | message | projectID | noteType |
+----+---------+------------+----------+
| 1 | 1 | 125 | update |
| 2 | 2 | 125 | update |
| 3 | 3 | 125 | update |
| 4 | 4 | 125 | update |
| 5 | 5 | 125 | update |
| 6 | 6 | 125 | update |
My query using the suggestion below:
SELECT `p`.`id`, `proName`, `p`.`proType`, `p`.`priority`,
`p`.`busSegment`, `p`.`portfolio`, `p`.`description`,
(SELECT group_concat('<li>', `message`, '</li>') AS temp FROM (SELECT
projectID, message FROM notes where projectID = p.id AND noteType =
'update' ORDER BY id DESC LIMIT 3) three_messages GROUP BY projectID) as
updates
FROM `projects` as `p`
WHERE `p`.`id` = 125
Error:
Error Code: 1054. Unknown column 'p.id' in 'where clause'
All records are returned. For some reason, the LIMIT 3 is not working.
The suggestion query work by it self.
SELECT group_concat('<li>', `message`, '</li>') AS updates
FROM (
SELECT projectID, message
FROM notes where projectID = 125 AND noteType = 'update'
ORDER BY id DESC
LIMIT 3
) three_messages
GROUP BY projectID;
+---------------------+
| updates |
+---------------------+
| 6,5,4 |
+---------------------+