I have a series of queries I need to run. They are monotonous and almost all of them use the same foreign key (trial_id). Is there a way to turn all these individual queries to one query that will post all results that I need?
select count(*) as totalstudies from study;
select count(*) as deletedstudies from study where trial_id = (select id from trial where name = 'abc');
select count(*) as portalemaillog from portalemaillog;
select count(*) as deletedemaillog from portalemaillog where trial_id = (select id from trial where name = 'abc');
select count(*) as totalsites from trialsite;
select count(*) as deletedsites from trialsite where trial_id = (select id from trial where name = 'abc');
select count(*) as totalsubjects from trialsubject;
select count(*) as deletedsubjects from trialsubject where trial_id = (select id from trial where name = 'abc');
select count(*) as totaltimepointcount from timepoint;
select count(*) as deletedtimepointcount from timepoint where id = (select id from trialversion where id = (select id from trial where name = 'abc'));
SELECT COUNT(*) AS deletedstudies FROM study AS s INNER JOIN trial AS t ON s.trial_id = t.id WHERE t.name = 'abc';SELECT (SELECT COUNT(*) FROM a) AS a_rows, (SELECT COUNT(*) FROM b) AS b_rows, (SELECT COUNT(*) FROM c) AS c_rows;