-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
  • 21,987
  • 13
  • 41
  • 69
JaRoi
  • 43
  • 8
  • As per the question guide, please do not post images of code, data, error messages, etc. - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. And please show what you’ve tried and tell us what you found (on this site or elsewhere) and why it didn’t meet your needs. – Dale K Jun 25 '21 at 08:14
  • Does this answer your question? [Comma separated results in SQL](https://stackoverflow.com/questions/18870326/comma-separated-results-in-sql) – Larnu 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
  • 19,456
  • 3
  • 10
  • 28