locked
How to make single query? RRS feed

  • Question

  • User1042252450 posted

    Hi all,

     How to write the following UNION query in a single query

    select distinct p.PatientId from Patient p
    inner join PatientParticipant pp on pp.PatientId=p.PatientId
    where pp.ClientID=245 and p.LastName like 's%' and pp.IsActive=1 and 
    p.PatientId in (select PatientId from PatientUser)
    union all
    select distinct p.PatientId from Patient p
    inner join PatientParticipant pp on pp.PatientId=p.PatientId
    where pp.ClientID=245 and p.LastName like 's%' and pp.IsActive=1 and 
    p.PatientId not in (select PatientId from PatientUser) and p.PatientId in (select PatientId from UserPatientClientFeature)
    and p.DateOfBirth > '2002-10-09'

    Thanks!

    Monday, October 12, 2015 7:27 AM

Answers

  • User-1596463 posted

    Hi v_rangasamy.

    Use this one

    select distinct p.PatientId from Patient p
    inner join PatientParticipant pp on pp.PatientId=p.PatientId
    where pp.ClientID=245 and p.LastName like 's%' and pp.IsActive=1 and 
    ((p.PatientId in (select PatientId from PatientUser)) or
    (p.PatientId not in (select PatientId from PatientUser) and p.PatientId in (select PatientId from UserPatientClientFeature)
    and p.DateOfBirth > '2002-10-09')

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 12, 2015 7:41 AM