I am using django, i want to implement a condition evaluating specific fields in a subquery, for instance:
SELECT a, b, c FROM letters
WHERE row(a,b) IN (
SELECT a, b FROM other_letters
)
can i do a row filter in django?
I don't think this is currently possible as of Django 3.1
.
You will have to use multiple subqueries if you want to use the ORM:
a = OtherLetters.objects.all().values('a')
b = OtherLetters.objects.all().values('b')
letters = Letters.objects.filter(a__in=a, b__in=b).values('a', 'b', 'c')
This is roughly equivalent to the following:
SELECT a, b, c FROM Letters
WHERE (
a IN (SELECT a FROM OtherLetters) AND
b IN (SELECT b FROM OtherLetters)
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.