Welcome to Microsoft T-SQL Q&A Forum!
Try this:
;With cte as
(
SELECT Name, UserID, SiteID FROM dbo.eventlog1
intersect
SELECT Name, UserID, SiteID FROM dbo.eventlog2
)
select * from cte
group by SiteID, UserID, Name
order by Name asc
IF you want to know more about the usage of intersect,you can look this document.
Best regards,
Bert Zhou
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.