I am writing a query in SQL to be used for SSRS 2005 which is
select t1.Category, t2.condition,'1' as hasCondition from t1
left outer join t2 on t1.ID = t2.ID
left outer join t3 on t2.cID = t3.cID
where t3.clientID = 6
union
select t1.Category, t2.condition, '0' as hasCondition from t1
left outer join t2 on t1.ID = t2.ID
and it returns the data as:
Category Condition hasCondition
Behavioural Tourette's Syndrome 0
Communications Impaired Speech 0
Dexterity Osteoarthritus 0
Dexterity Osteoporosis 0
Dexterity Other Dexterity 0
Dexterity Rheumatoid Arthritus 0
Emotional Bipolar Disorder 0
Emotional Clinical Depression 0
Emotional Depression 0
Emotional Depression 1
Emotional Gulf War Syndrome 0
Emotional Gulf War Syndrome 1
Now I want to select only one record from duplicates rows/results for example:
Category-Emotional, condition-Depression which hasCondition ‘1’ or ‘true’
I hope I made it clear using the example.
Please help me.
Thanks.
It’s not 100% clear what you want, but I think you’re just looking for the MAX() of the final field…
If you wanted to simplify that whole query…