Question: I have a social network I am coding but it's a bit different than others, in this case there is only ever one status show per user on a feed section.

So I need to sort the status by date with the latest ones on top but also group by the userID
unfortunately I can't seem to get this working....

This is my current query:

```
SELECT *
FROM status
WHERE userID != "83" #This is just so my statuses don't show
GROUP BY userID
ORDER BY addedDate DESC
LIMIT 10

```

I expect to see the latest status results and only one per user instead I see the first statuses so the group by is working but not the order by.

Thanks in advance.

Answer: 
As mentioned in the comments to [Robin's answer](https://stackoverflow.com/a/10550415/623041), that approach is unreliable because MySQL does not guarantee that it will always return the most recent status from each group. You must instead join your table with a subquery that selects the most recent status (based on `addedDate`).

```
SELECT   *
FROM     status
  NATURAL JOIN (
    SELECT   userID, MAX(addedDate) as addedDate
    FROM     status
    GROUP BY userID
  ) AS mostRecent
ORDER BY addedDate DESC
LIMIT    10

```

Note that if a user has multiple status updates with the same `addedDate`, the server will return all of them (whereas Robin's query would return an indeterminate one); if you need control over such a situation, you will need to define how one determines which such status update should be selected.
```
SELECT *
FROM (  SELECT *
        FROM status
        WHERE userID != "83"
        ORDER BY addedDate DESC) AS h
GROUP BY userID
ORDER BY addedDate DESC
LIMIT 10

```

You must ORDER BY before GROUP BY'ing.

[**Example 1**](https://stackoverflow.com/questions/10497635/how-to-write-inner-query-that-returns-latest-message-for-a-given-user/10497700#10497700)  

[**Example 2**](https://stackoverflow.com/questions/7436973/use-group-by-in-mysql-and-return-identity-of-the-row/7437076#7437076)