How to use group by clause to fetch related data
Posted In:
Django
.
By CreativeSolutions
There is no exact group by clause and we can use the function annotate to get the count of records with grouping data.
If we need to fetch the related data from 2 tables,
first we need to fetch the unique data from first table
then we can use the filter function with id__in
ex:
mapdata = MedicationMapping.objects.all()
meds = Medication.objects.filter(id__in=mapdata)
If we need to fetch the related data from 2 tables,
first we need to fetch the unique data from first table
then we can use the filter function with id__in
ex:
mapdata = MedicationMapping.objects.all()
meds = Medication.objects.filter(id__in=mapdata)
0 Responses to How to use group by clause to fetch related data
Something to say?