-1

Table "Module" has these columns

enter image description here

How to select distinct columns of ModuleGroupDisplayAs and ModuleGroup And After that, Add column on checking these distinct columns has particular UserID and CompanyID. That means I want to check condition that distinct columns has this particular userID and CompanyID. The expected result would be as following.

enter image description here

Dale K
  • 25,246
  • 15
  • 42
  • 71
JaRoi
  • 65
  • 8
  • Does this answer your question? [Comma separated results in SQL](https://stackoverflow.com/questions/18870326/comma-separated-results-in-sql) – Thom A Jun 25 '21 at 08:14

1 Answers1

0

It looks like you just need to group by the last two columns and use a case expression to determine yes/no, but want Yes to override No to remove duplicates, for which you can use aggregations

select  
    Max(case when UserID='agnes' and CompanyID='aud' then 'Yes' else 'No' end) as [Include?],
    ModuleGroupDisplayAs, ModuleGroup
from Module
group by ModuleGroupDisplayAs, ModuleGroup
Stu
  • 30,392
  • 6
  • 14
  • 33