create table if not exists article (id int); create table if not exists campaign (id int); create table if not exists post (id int); create table if not exists survey (id int); create table if not exists activity (id int); create table if not exists activity2 (id int); create table if not exists share (id int); SELECT groupby1.a1 AS c1 FROM ( SELECT count(1) AS A1 FROM (SELECT unionall4.c1 FROM (SELECT unionall3.c1 FROM (SELECT unionall2.c1 FROM (SELECT unionall1.id AS c1 FROM (SELECT extent1.id FROM campaign AS extent1 UNION ALL SELECT extent2.id FROM article AS extent2) AS unionall1 UNION ALL SELECT extent3.id FROM post AS extent3) AS unionall2 UNION ALL SELECT extent4.id FROM survey AS extent4) AS unionall3 UNION ALL SELECT extent5.id FROM activity AS extent5) AS unionall4 UNION ALL SELECT extent6.id FROM share AS extent6) AS unionall5 INNER JOIN activity2 AS extent7 ON unionall5.c1 = extent7.id GROUP BY extent7.id ) as groupby1;