Question: I'm using Parse.com, and have two classes: `User` and `Report`. A `User` may issue several reports during a day, but I'm only interested in the most recent one. However, I need to get all the reports that meet specific criteria, but only the most recent one.

The end result is an array of `Report`s, where the `User` is unique on each one, something like this:

```
ObjectId | ReportedValue | User | CreatedAt
1234     | 100           | aaaa | 2013-05-20T04:23:41.907Z
1235     | 100           | bbbb | 2013-04-29T05:10:41.907Z
1236     | 100           | cccc | 2013-05-20T02:14:41.907Z
1237     | 100           | dddd | 2013-05-19T04:03:41.907Z

```

So, `User` aaaa might have 20 reports, but I only need the most recent, for each user. However, I'm searching based on the `ReportedValue` being `100`, and the desired result is the report objects, not the user, so I'd prefer not to go through every user.

Is this possible in Parse?

Answer: 
```
UPDATE likesd a, (SELECT Parent, SUM(Votes) as TotalVotes
                  FROM likesd
                  GROUP BY Parent) b
SET a.Votes = b.TotalVotes
WHERE a.Type = 2
    AND a.id = b.parent

```

Reference: [You can't specify target table for update in FROM clause](https://stackoverflow.com/questions/4429319/you-cant-specify-target-table-for-update-in-from-clause/4429409#comment20742824_4429409)
Try like this...

```
  UPDATE  likesd  inner join 
(Select id, ifnull((Select Sum(Votes) from Likesd A where A.parent=B.Id),0) as suvotes from Likesd) B on B.id=likesd.Id
    Set likesd.Votes=B.suvotes
    where type=2

```