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)
yoU can't specify the taget table in from when select and update from same table. This cant be done without procedure. There is one way of doing this if you want.

```
CREATE TABLE temp SELECT * FROM likesd;
UPDATE  likesd  B
SET B.votes=(SELECT SUM(votes) FROM temp A WHERE  A.parent=B.TYPE)
WHERE TYPE=2; 
DROP TABLE temp;

```

Run all queries one by one in your code.