Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I'm trying to figure out how to write a 'not in' style query in Django. For example, the query structure I'm thinking of would look like this.

select table1.* 

from table1

where table1.id not in 

(

  select table2.key_to_table1

  from table2 

  where table2.id = some_parm 

)

What would the Django syntax look like assuming models called table1 and table2?

1 Answer

0 votes
by (40.7k points)

Try using exclude like this:

Table.objects.exclude(title__in=myListOfTitles)

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...