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 8286393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:45:06+00:00 2026-06-08T11:45:06+00:00

My where exists clause isn’t working. What trivial thing am I missing? select *

  • 0

My where exists clause isn’t working. What trivial thing am I missing?

select * from patient as p
where exists
(
    select p.patientid, count(*) from tblclaims as c 
    inner join patient as p on p.patientid=c.patientid
    and p.admissiondate = c.admissiondate
    and p.dischargedate = c.dischargedate
    group by p.patientid
    having count(*)>500
)

patient and tblclaims are joined together by the three-field composite key as as you can see in the query.

  • 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-08T11:45:08+00:00Added an answer on June 8, 2026 at 11:45 am

    The count(*) from tblclaims as c is unnecessary and could be throwing the query off.

    Also, you have no WHERE clause joining patient p to your exists clause.

    Not to mention you use p as an alias in both the main query and the exists clause, which is just confusing.

    You probably want something like:

    select * from patient
    where exists
    (
        select p.patientid 
        from tblclaims as c 
        inner join patient as p on p.patientid=c.patientid
            and p.admissiondate = c.admissiondate
            and p.dischargedate = c.dischargedate
        where patient.patientid = p.patientid
        group by p.patientid
        having count(*)>500
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this condition as part of my where clause: exists (select *
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'myTrigger' AND type = 'TR')
I have a SELECT query across 2 tables that isn't returning any results and
I'm struggling to convert the following (simplified) HQL to QueryOver: select subscription from Subscription
I'm working in SQL Server 2008, and I'm trying to select into a temp
I have a query like this SELECT tbl_products.*, GROUP_CONCAT(tags.name) FROM tbl_page_collections_products, (SELECT page_collection_name as
I've got a question about working with entities which were received from db. Currently
I am trying to tune SQLs which have NOT EXISTS clause in the queries.My
I'm having trouble translating an existing TSQL query with a Not Exist clause into
Exists a way to call .net assemblies more specific .dll files in java? I

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.