'django: JOIN two SELECT statement results

MYSQL - working fine

SELECT
    *
FROM 
    (SELECT ...) u
LEFT JOIN
    (SELECT ...) e
ON
    (u.id = e.employee_id)

DJANGO

    u = user_with_full_info.objects.values(
            'id'
        ).filter(
            branch = team['branch__id'], 
            team = team['team__id'], 
            position__lt = team['position__id'], 
            valid = 1
        )

    d = staff_review.objects.values(
            'employee'
        ).annotate(
            last_date=Max('date'), 
            dcount=Count('employee')
        ).filter(
            month = month()
        )    
   
    e = staff_review.objects.values(
            'performance__name', 
            'performance__style', 
            'employee__user__id', 
            'employee__user__salary_number', 
            'employee__user__last_name', 
            'employee__user__mid_name', 
            'employee__user__first_name',
            'date'
        ).filter(
            month = month(),
            employee__id__in = Subquery(u.values('id')), 
            date__in = Subquery(d.values('last_date')), 
        ).order_by(
            'employee__id'
        )

With MYSQL I got: | employee_id | performance_id | | -------- | -------------- | | 3 | 2 | | 1 | 3 | | 4 | NULL |

With Django I got: | employee_id | performance_id | | -------- | -------------- | | 3 | 2 | | 1 | 3 |

How can I fix that? How can I make a left join "u" with "e"?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source