Combine two tables with 2 PK - Table 1 has the column (id12) that holds data for Table 2 column (sub_obje_id)

by Timmy Aroyewun   Last Updated October 19, 2019 18:06 PM

SELECT COUNT(id12) AS PROG_AREA
FROM [dbo].[header_record]
INNER JOIN dbo.header_record.id12 = dbo.object.sub_obje_id
ON
(SELECT
pool_id AS 'Pool',
CASE 
WHEN sub_obje_id = 4104 THEN 'TV Script'
WHEN sub_obje_id = 4105 THEN 'TV Running Order'
WHEN sub_obje_id = 4152 THEN 'Radio Script'
WHEN sub_obje_id = 4158 THEN 'Radio Running Order'
END AS "Type",
COUNT(*) AS '#Records'

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.sub_obje_id ASC


Related Questions


Updated February 10, 2017 14:02 PM

Updated June 03, 2019 02:06 AM

Updated March 09, 2018 14:06 PM

Updated January 17, 2019 00:06 AM

Updated April 03, 2019 11:06 AM