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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:29:36+00:00 2026-06-08T10:29:36+00:00

Revised Again: SELECT x.Imaging, x.Indication FROM medicalimaging x WHERE MCGID = ‘1036’ and x.Indication

  • 0

Revised Again:

SELECT x.Imaging, x.Indication FROM medicalimaging x 
 WHERE MCGID = '1036' 
and x.Indication not in (
select Indication FROM invoicefields a join invoices b on a.InvoiceNumber = b.InvoiceNumber WHERE a.PatientID = '10120003' and x.MCGID = b.StudyID and x.Imaging = a.TypeOfExam
)
Order By Imaging ASC, Indication ASC

Thank you all for your answers, I did some research and this is what I cam up with.

SELECT x.Imaging, x.Indication
FROM medicalimaging x
WHERE MCGID =  'McG 1032'
AND x.Indication NOT 
IN (

SELECT Indication
FROM invoicefields a
JOIN invoices b ON a.InvoiceNumber = b.InvoiceNumber
WHERE a.PatientID =  '10120003'
AND x.MCGID = b.StudyID
)

I am trying to figure out what already has been invoiced and exclude it from a list. These are my tables, some sample data, and the query results.

Medical Imaging ( These are the fields to be used in the list)
id | MCGID | Imaging | Indication 
1    1032     Xray       Visit 1
2    1032     Xray       Visit 2
3    1032     Xray       Visit 3
4    1032     CT         Emergency
5    1045     Xray       Initial

invoice ( Generic Invoice Data)
InvoiceNumber | StudyID |     TypeInvoice       | void | 
     1            1032        Medical Imaging        0 
     2            1045        Medical Imaging        0
     3            1032        Medical Imaging        1
     4            1032        Medical Imaging        0 

Invoicefields ( The Rows of charges in the Invoice ) 
InvoiceNumber     |    PatientID   |    TypeofExam   | Indication 
1                   PT25        Xray            Visit 1   
1                   PT30        Xray            Visit 1   
2                   PT36        Xray            Initial
2                   PT25        Xray            Initial
4                   PT25        Xray            Visit 2   
4                   PT30        Xray            Visit 2   
4                   PT25        Xray            Visit 3   

After Query Results


Ex. 1 Provided  MCGID=1032  and PatientID=PT25.

Results:   CT , Emergency


Ex. 2 Provided  MCGID=1032  and PatientID=PT30.


Results:           Xray    ,    Visit 3         
                   CT       ,   Emergency

So, This is the generic structure. For reference, MCGID is the SAME as StudyID, and Type of Exam is the SAME as Imaging. Another thing to note is MCGID is unique, and PatientID is only unique to the MCGID. This means that the PatientID can be reused for another MCGID. For the Query to run, I will provide it with PatientID, and MCGID. So my goal is to create a list of potential Imaging and Indications that are not listed in the invoicefields under TypeofExam and Indication. Also, it should also ignore the invoice number if void=1.

EDIT :

I understand basic sql functions, I understand how to pull data from multiple tables, I just dont get how to cross reference data from multiple tables. The issue is I have to cross reference data about 3 times. So this is where I am at now.

SELECT medicalimaging.Imaging,medicalimaging.Indication FROM medicalimaging WHERE MCGID='1032'

I am just not sure how to tell it to get the data from the other tables and compare it to the data I am about to pull.

  • 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-08T10:29:39+00:00Added an answer on June 8, 2026 at 10:29 am

    Easiest solution is to use exist to find Imaging data having invoices and exclude them:

    select *
     from MedicalImaging mi
     where mi.mcgid = 1032
       and not exists (select null
                         from Invoice i
                        inner join InvoiceFields f
                           on i.invoicenumber = f.invoicenumber
                        where i.studyid = mi.mcgid
                          and i.void = 0
                          and f.typeOfExam = mi.imaging
                          and f.Indication = mi.indication
                          and f.PatientID = 'PT30')
    

    I had to be creative here. I’ve added InvoiceFields.Indication = MedicalImaging.Indication to be able to narrow down repeated exams. The reasoning behind this schema is unclear to me. Perhaps you have undisclosed tables concerning patients that would explain how you know which PatientID to supply for this query to work.

    Here is DEMO @ Sql Fiddle. You might alter schema there to provide more informations, and post a link back.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

* revised, but still not solved...* I want to combine data from two files
I followed RailsCasts authentication from scratch (http://railscasts.com/episodes/250-authentication-from-scratch-revised) using the bcrypt-ruby gem and have the
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
[revised] I'm creating a TreePanel in ExtJs that is loading its children from a
I have a form that once you select from a drop-down list and select
EDIT: To answer some questions, this is the revised and still not working code
Is there any idea not to select the name that is already chosen in
REVISED FROM OLD QUESTION- NOW USING DIFFERENT WAY FORWARD I am building a chatbox
Revised: I have a list items on the page that I'm creating from database
REVISED... The crux of the app is communicating with a database server. Responses from

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.