# Part1 Annotating Exercises not understanding

**URL:** https://forum.codewithmosh.com/t/part1-annotating-exercises-not-understanding/19668
**Category:** Django
**Created:** [April 18, 2023, 8:41am UTC](https://forum.codewithmosh.com/t/part1-annotating-exercises-not-understanding/19668 "2023-04-18T08:41:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![momo](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@momo](https://forum.codewithmosh.com/u/momo)
#### Post date: [April 18, 2023, 8:41am UTC](https://forum.codewithmosh.com/t/part1-annotating-exercises-not-understanding/19668/1 "2023-04-18T08:41:17Z")

</div>

> Write code to get: •Customers with their last order ID

what I expected:

```auto
  queryset = Customer.objects.annotate(
        last_order_id = ('order__id').order_by('order__placed_at') 
    )

```

which solution is

 ![Screenshot 2023-04-18 at 17.39.18](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/2/2355bc56f0e10930d33d51e086a3a9ce92378af9.png)

in database, the last order by user 1 is 321, the solution gives 931  
321, **2021-03-17** 00:00:00.000000,F,1  
403,2021-02-25 00:00:00.000000,P,1  
540,2020-08-25 00:00:00.000000,F,1  
544,2020-10-31 00:00:00.000000,F,1  
931,2020-12-19 00:00:00.000000,C,1

# why solution use MAX? why order\_\_id not order\_id

---

<div class="post-metadata">

### Author: ![momo](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@momo](https://forum.codewithmosh.com/u/momo)
#### Post date: [April 19, 2023, 7:48am UTC](https://forum.codewithmosh.com/t/part1-annotating-exercises-not-understanding/19668/2 "2023-04-19T07:48:06Z")

</div>

I find out my solution that satisfied me

```auto
    latest = Order.objects.filter(customer=OuterRef('pk')).order_by('-placed_at')

    queryset = Customer.objects.annotate(
        latest_order=Subquery(latest.values('id')[:1]))

```
