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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:20:57+00:00 2026-05-25T03:20:57+00:00

I have a 3 table structure such that: Table Patient – PatientID PK has

  • 0

I have a 3 table structure such that:

Table Patient – PatientID PK has a 1 to many relationship with table Appointment (PK ApptID)
Table Appointment has a 1 to many relationship with table Encounter (PK EncounterID).
ApptID is a FK for Encounter table.

Encounter table has a few notable fields. PK: EncounterID, FK: ApptID, DateofEncounter (datetime), and Code (varchar). The last two are not keys or anything.

What I want to do search for duplicate encounters that have the same code, same ApptID, and same DateoFEncounter. I want a list by PatientID, then ApptID

I have this SQL which lists PatientID, ApptID, and # of Encounters. But I don’t know if those encounters are duplicates or not. (they could be on different dates, or different codes, or what not). I have no clue how to find those that occur on the same date with the same code. Any advice?

select a.PatientID, a.ApptID, COUNT(e.EncounterID) AS NumberOfEncounters
FROM Appointment a LEFT JOIN Encounter e on e.ApptID = a.ApptID
GROUP BY a.PatientID, a.ApptID
ORDER BY COUNT(e.EncounterID) DESC
  • 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-05-25T03:20:58+00:00Added an answer on May 25, 2026 at 3:20 am
    select a.PatientID, a.ApptID, COUNT(e.EncounterID) AS NumberOfEncounters
    FROM Appointment a LEFT JOIN Encounter e on e.ApptID = a.ApptID
                                AND EXISTS (SELECT * FROM Encounter e2 WHERE e.pkEncounterID <> e2.pkEncounterID AND e.Code = e2.Code AND e.DateofEncounter = e2.DateofEncounter AND e.ApptID = e2.ApptID)
    GROUP BY a.PatientID, a.ApptID
    ORDER BY COUNT(e.EncounterID) DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database structure that has a Person table which contains fields such
I have a few classes, such as those that outline database table structure or
So I have an SQL Table structure such that I have Blogs which have
I have a table structure that looks like: <table> <tr id=row1> <td> <div>row 1
I currently have a table structure that looks something like this(some details omitted): ColumnName
I have a table with such structure: uid sid all integers. This table simulates
I have a data-structure such that: SecurityPolicy 1<---* SecurityPolicyRule Therefore, a SecurityPolicy can have
I have an object structure that is mimicking the properties of an excel table.
i have table structure with 3 colums (column1, column2, column3) and i want to
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party

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.