Select distinct(job_id) from A where condition
Select distinct(job_id) from B where condition
Select distinct(job_id) from C where condition
Here may be 1,2 and 3 have some common jobId
What I need is count of all job_id which may not get repeated.
2
Answers
With UNION ?
I believe
EXCEPT
is what you might be looking for here which provides a disjoint result set across multiple queries. This could probably be handled withJOIN
logic also but it’s a little hard to tell with the limited detail in the question.Here is the Postgres documentation on the
EXCEPT
keyword.Here is a solution that works but is not scalable. I’m hesitant to post it because I feel like it’s ugly and there must be a better way but maybe this will point you in the right direction.
DBFiddle to show a working example.