agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: pgsql-sql@postgresql.org
Subject: left outer join with count
Date: Fri, 29 May 2020 17:09:16 +0100
Message-ID: <202005291709.16647.gary.stainburn@ringways.co.uk> (raw)
I have the following select:
select sj.*, sr.*, wd.doc_count from
service_jobs sj
left outer join service_receptions sr on sr.sr_id = sj.sj_sr_id
left outer join (select sj_id, count(sj_id) as doc_count from work_documents wd group by sj_id) wd on wd.wd_sj_id = sj.sj_id;
While the select works, I can't help thinking that the last join is expensive. Is there a cleaner (quicker) method of doing this?
Gary
view thread (3+ messages) latest in thread
Message-ID: <202005291709.16647.gary.stainburn@ringways.co.uk>
Permalink: ../202005291709.16647.gary.stainburn@ringways.co.uk/
Also on: postgresql.org/message-id/202005291709.16647.gary.stainburn@ringways.co.uk
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gary.stainburn@ringways.co.uk
Subject: Re: left outer join with count
In-Reply-To: <202005291709.16647.gary.stainburn@ringways.co.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox