We need to create a view that combines both these SQL statements together.
SELECT g.state_cd, g.state_name,
case when s.ROLE_ID = 110 then 'Yes' else 'No' end POC
FROM us_state g
LEFT OUTER JOIN role s ON g.state_cd = s.OFC_STATE_CD
and s.role_id = 110
SELECT g.state_cd, g.state_name,
case when s.ROLE_ID = 120 then 'Yes' else 'No' end ADM
FROM us_state g
LEFT OUTER JOIN role s ON g.state_cd = s.OFC_STATE_CD
and s.role_id = 120
Eg.
An user will have multiple rows. Some users will have role = 110 & some users will have role = 120 & some will have a combination of both. So is it possible to create 1 SQL statement that combines both of these. The result should be:
MD Maryland Yes No
NY Newyork No Yes
NJ Newhersey Yes Yes
The above table implies:
MD user has only role of 110
NY user has only the role of 120
NJ user has both roles.
Hope I’m clear on what is needed & it makes sense.
I tried to combine them like this:
SELECT g.state_cd, g.state_name,
case when s.ROLE_ID = 110 then 'Yes' else 'No' end POC,
case when s.ROLE_ID = 120 then 'Yes' else 'No' end ADM
FROM us_state g
LEFT OUTER JOIN role s ON g.state_cd = s.OFC_STATE_CD
and s.role_id in (110, 120)
But this doesn’t work and it returns duplicate rows. Not sure what I’m missing here. I would appreciate it greatly if someone can help.
Thanks
Harish
You need to aggregate the results:
It turns out that “Yes” and “No” work well with MAX.