Combine two tables with 2 PKs – Table 1 contains the column (id12) that contains the data in column 2 (sub_obje_id).

SELECT COUNT (id12) AS PROG_AREA
FROM (dbo). (Header_record)
INNER JOIN dbo.header_record.id12 = dbo.object.sub_obje_id
SURE
(TO SELECT
pool_id AS & # 39; Pool & # 39;
CASE
WHEN sub_obje_id = 4104 THEN & # 39; Script TV & # 39;
WHEN sub_obje_id = 4105 THEN & # 39; TV order of passage & # 39;
WHEN sub_obje_id = 4152 THEN & # 39; Script radio & # 39;
WHEN sub_obje_id = 4158 THEN & # 39; Radio operation order & # 39;
END AS "Type",
COUNT (*) AS '# Records & # 39;

FROM (dbo). (Object)
WHERE pool_id <> 0 AND sub_obje_id IN (4104,4105,4152,4158)
GROUP BY pool_id, sub_obje_id)
–ORDER BY ob.sob_obje_id ASC