Im working on status table I’ll show basic information per user and what filtering needs to happen having an issue getting the latest status per user and grouping by user.
So the status table information that I need to use is:
- ID
- content
- userID
and the user information I need to use is:
- ID
- locationID
So the end result of what I want to achieve is having is the latest status of each user grouped by user.
I was using:
SELECT ID, content
FROM status
WHERE content NOT RLIKE "#[0-9azA-Z]"
AND type = "5"
AND userID IN (
SELECT DISTINCT ID
FROM users
WHERE hometownID = "'.$locationID.'"
OR locationID = "'.$locationID.'"
)
GROUP BY status.userID
ORDER BY addedDate DESC
And then I was grouping by user in PHP using an array of already added users and excluding them, but this is not ideal for scaling up and loading more results after, so I want a SQL only solution.
Thanks in advance.
This is working for me!