Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8710771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:42:36+00:00 2026-06-13T04:42:36+00:00

I am writing a query in SQL to be used for SSRS 2005 which

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:42:38+00:00Added an answer on June 13, 2026 at 4:42 am

    It’s not 100% clear what you want, but I think you’re just looking for the MAX() of the final field…

    SELECT
      category, condition, MAX(has_condition) AS hasCondition
    FROM
    (
      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
    )
      AS data
    GROUP BY
      category, condition
    

    If you wanted to simplify that whole query…

      select
        t1.Category,
        t2.condition,
        MAX(CASE WHEN t3.clientID = 6 THEN 1 ELSE 0 END) as hasCondition
      from
        t1
      left outer join
        t2
          on  t2.ID = t1.ID
      left outer join
        t3
          on  t3.cID = t2.cID
          and t3.clientID = 6 
      group by
        t1.Category,
        t2.condition
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Writing an SQL query to SELECT item from the following table I
I am writing an SQL query which involves finding if timestamp falls in particular
I wrote a sql join query in oracle with two table. While writing query
I'm writing a query and as I go along I'm analysing the SQL Profiler
I'm writing a PHP script that builds an SQL query by concatenating the string
I am writing some new SQL queries and want to check the query plans
I am writing a query which needs to return all child entries (and their
I'm writing some JDBC code which calls a Oracle 11g PL/SQL procdedure which has
I am writing a ODBC-database class which contains a member function used to fetch
I'm writing a query, and have used the solution in this thread and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.