by comment type, i want to create new columns. but for each invg_id, it's giving me 2 lines. how do i make it 1 line per invg_id
select f.INVG_ID, case when f.COM_TYPE = 28 then f.MaxCmtInvgDt end as 'MaxAgentSFRDt',
case when f.COM_TYPE = 28 then f.CmtAddedBy end as 'MaxAgentSFRAddedBy',
case when f.COM_TYPE = 28 then c.COM_DETAILS end as 'AgentSFRComment',
case when f.COM_TYPE = 29 then f.MaxCmtInvgDt end as 'MaxSupSFRDt',
case when f.COM_TYPE = 29 then f.CmtAddedBy end as 'MaxSupSFRAddedBy',
case when f.COM_TYPE = 29 then c.COM_DETAILS end as 'SupSFRComment'
from RPT_OBJ_PRD.RPT.RO_CMT_FACT f
join OIGES_TRAN_PRD.IM.COMMENTS c
on c.com_id = f.COM_ID
where f.COM_TYPE in (28, 29)
and f.MaxCmtInvg = 1
order by f.INVG_ID desc
select
f.INVG_ID,
max(case when f.COM_TYPE = 28 then f.MaxCmtInvgDt end) as 'MaxAgentSFRDt',
max(case when f.COM_TYPE = 28 then f.CmtAddedBy end) as 'MaxAgentSFRAddedBy',
max(case when f.COM_TYPE = 28 then c.COM_DETAILS end) as 'AgentSFRComment',
max(case when f.COM_TYPE = 29 then f.MaxCmtInvgDt end) as 'MaxSupSFRDt',
max(case when f.COM_TYPE = 29 then f.CmtAddedBy end) as 'MaxSupSFRAddedBy',
max(case when f.COM_TYPE = 29 then c.COM_DETAILS end) as 'SupSFRComment'
from RPT_OBJ_PRD.RPT.RO_CMT_FACT f
inner join OIGES_TRAN_PRD.IM.COMMENTS c
on c.com_id = f.COM_ID
where f.COM_TYPE in (28, 29)
and f.MaxCmtInvg = 1
group by f.INVG_ID
order by f.INVG_ID desc