In this query i can get the event_name which occurs with both types of worker role. But I want to have all of the rows showing and then some kind of tic column to show that the ones that match both conditions, ie in both types of worker roles.
select wv1.worker_role, wv1.event_name from event_worker_role_view wv1 where wv1.worker_role in('A31 Service Provider')
and wv1.event_name in (select wv2.event_name from event_worker_role_view wv2 where
wv2.worker_role = 'A29i Licensed Clinician')
How would you make the join? this did not work-Incorrect syntax near the keyword 'inner'.
select wv1.worker_role, wv1.event_name from event_worker_role_view wv1 where wv1.worker_role in('A31 Service Provider')
and wv1.event_name in (select wv2.event_name from event_worker_role_view wv2 where
wv2.worker_role = 'A29i Licensed Clinician')
inner join event_worker_role_view wv2
on wv1.worker_role = wv2.worker_role
As mentioned before, you will get better answers if you take the time to provide consumable test data.
Also, it would probably be more efficient to work with the tables and not a view.
At a guess:
WITH Both
AS
(
SELECT event_name
FROM dbo.event_worker_role_view
WHERE worker_role IN ('A31 Service Provider', 'A29i Licensed Clinician')
GROUP BY event_name
HAVING COUNT(DISTINCT worker_role) = 2
)
SELECT WR.worker_role, WR.event_name
,CASE
WHEN B.event_name IS NOT NULL
THEN 'Y'
ELSE 'N'
END AS Both
FROM dbo.event_worker_role_view WR
LEFT JOIN Both B
ON WR.event_name = B.event_name;