Question

Locked

Help with a SQL query

By jimmy-jam ·
Wondering if someone can help me write a SQL query. I have a table that contains a bunch of patient data. Each patient has a medical record number assigned to a study. Each study has a unique study reference number which is the primary key. Long story short, I need to write a query that returns one line for each unique medical record number with some other data. Basically like this.

SELECT patient_id, patient_name, DOB from table

this is where I get stuck, I need to somehow incorporate some syntax where I only get one entry per unique or distinct patient id. Hopefully that makes sense.

This conversation is currently closed to new comments.

14 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Is the date in multiple tables? Single table?

by LocoLobo In reply to Help with a SQL query

Are you looking strictly for distinct rows for patient ids, names and DOB? Or are you looking for something else?

Collapse -

Reponse To Answer

by jimmy-jam In reply to Is the date in multiple t ...

It's a single table. I only want one result per Patient ID.

Collapse -

Have you tried

by LocoLobo In reply to Help with a SQL query

Select distinct id, name, DOB from table

Collapse -

This?

by ispyty In reply to Help with a SQL query

SELECT patient_id, patient_name, DOB
FROM table
GROUP BY patient_id

Is that what you were looking for?

Collapse -

Reponse To Answer

by jimmy-jam In reply to This?

That query wouldn't give me only one line per patient_id.

Collapse -

Patient Privacy Act

by bsongy In reply to Help with a SQL query

I have no tech advise, but be careful. You are, without the proper permissions, dancing dangerously close to a violation of HIPAA's Patient Privacy rules. The joint commission could potentially see some of this as a violation. Check with your HIM department, or Enterprise/EPIC departments.

Collapse -

Reponse To Answer

by mychitterman In reply to Patient Privacy Act

It could just be his assignment for school! However, I am very happy that you have identified this. Health Care Info System workers need to be on Top the Biz Analytic path.

Collapse -

Reponse To Answer

by jimmy-jam In reply to Patient Privacy Act

I appreciate your concern and they are duly noted. I work for a medical imaging company and am well aware of HIPAA and my responsibility to protect the privacy of patients. I would never dream of posting and Personally Identifiable Information on a public forum.

Collapse -

Multlple Entries

by AssemblerRookie In reply to Help with a SQL query

for a customer ID in a table(s) will return multiple records, which it should do, in a pure SQL query. What you need to do is post process this returned data to display in your user interface (front end).
EG Table "Data"
Cust_ID Cust_Name Cust_DOB Cust_MisInfo
1 A Name 5/5/AYear 2 Yr Contract
1 A Name 5/5/AYear Terminated
2 B Name 4/4/AYear 1 Yr Contract
SQL Statement "SELECT Cust_ID,Cust_Name,Cust_DOB,Cust_MisInfo FROM Data WHERE Cust_ID = 1;"
The statement above will return two records as it appears in the table(s).

Collapse -

One patient participating in 2 studies

by phil232 In reply to Help with a SQL query

will always output 2 lines in a query involving patient and study data. If you want to list that in a (HTML, f.ex.) table you have to execute one query to get all patients and then for each patient you have to SELECT * FROM Studies WHERE Studies.Cust_ID = Patients.Cust_ID

But still consider bsongy's comment regarding joining patient data with study results. You may quite fast finish with a big fine whenever (and that's most of the time) the patient's (study) data are protected and have to be kept in a way that the study result remains absolutely anonymous.

Back to Web Development Forum
14 total posts (Page 1 of 2)   01 | 02   Next

Software Forums