Hello,
I would like some help from the core guys. I'm getting an error while executing the following query (the objective of this query is basically get the last created employee for each company):
Company.objects.annotate(Max('employee__pk')).filter(employee__pk=F('employee__pk__max'))
The error follows:
OperationalError: (1054, "Unknown column 'T3.id' in 'having clause'")
Not sure if my query is correct in the Django perspective but it's look OK when looking at DB level. There are some gotchas I noticed:
1 - It works in SQLite.
2 - If I change the field (eg: `employee__pk` to `employee__created`) it works fine. It seems to crash only when using PK.
4 - The generated SQL does not include the `T3.id` in the `SELECT` clause. If I add it through the `QuerySet#extras` the problem goes away.
Thanks in advance,
Paulo Poiati