Thursday, June 1, 2017

Re: count from multiple tables in a single query?

On Wednesday 31 May 2017 12:13:48 'Abraham Varricatt' via Django users wrote:

 

> If I want to get the total count from both tables it can be done like

> this,

>

> author_count = Author.objects.count()

> publisher_count = Publisher.objects.count()

>

> My concern is that this results in two different queries to the

> database. Can it be done with a single query call?

 

Why is that a concern? This isn't the kind of thing to optimize. Query optimization is about loops and relations. Not about getting information you need - it comes at a price. Have you timed what you could save?

--

Melvyn Sopacua

No comments:

Post a Comment