Select values which not in another table with Django

后端 未结 1 1212
一整个雨季
一整个雨季 2021-02-15 14:25

How this SQL query can be translated to Django ORM statement?

SELECT field1, field2, field3
FROM table1
WHERE field1 NOT IN 
(SELECT 2_field1 FROM table2);


        
相关标签:
1条回答
  • 2021-02-15 14:47

    Using two QuerySets, as shown in the docs.

    inner_qs = table2.objects.all()
    results = table1.objects.exclude(field1__in=inner_qs)
    
    0 讨论(0)
提交回复
热议问题