-
General Help with a Query Needed
OK, so I'm trying to get the admission id, name and ward name for patients who have been admitted but not operated on. The four tables used are PERSON, ADMISSION, OPERATION and WARD. Admission id and ward code are in admission, and Admission id is in admission and operation
What I have is:
SELECT ADMISSION.Admission_id, PERSON.First_name, PERSON.Surname, WARD.Ward_name
FROM ADMISSION, PERSON, WARD
Where ADMISSION.Patient_id = PERSON.Person_id
AND ADMISSION.Ward_code IS NOT NULL
AND ADMISSION_id NOT IN (SELECT ADMISSION_id FROM OPERATION);
This brings up six rows - the first two lines are correct, but then it gives additional lines for each of the two people for the other two ward names. I tried a nested select query to ispolate the Ward Codes for the two specific people but it didn't work.
Any ideas?
-
Do all four tables have a specific field that ties them altogether?
If not, they should, and you could then do a JOIN on those fields to further filter out your records.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
There is no one common thread throughout all four tables, but Admission_id is common in ADMISSION, PERSON and OPERATION and Ward_code is common in ADMISSION and WARD
-
Probably, this is only working on its where clause
Hi there,
According to what you have wrote, you might want to try this:
SELECT ADMISSION.Admission_id, PERSON.First_name, PERSON.Surname, WARD.Ward_name
FROM ADMISSION, PERSON, WARD
Where ADMISSION.Patient_id = PERSON.Person_id
AND ADMISSSION.ADMISSION_id = PERSON.ADMISSION_id
AND ADMISSION.Ward_code = WARD.Ward_code
AND ADMISSION.Ward_code IS NOT NULL
AND ADMISSION_id NOT IN (SELECT ADMISSION_id FROM OPERATION);
This might work. Otherwise, you only need to refine your where clause.
Best regards,
Tonci Korsano
"A supercomputer is to a computer, what Superman is to a man. Wake up and smell power!"
Similar Threads
-
By peljo in forum Database
Replies: 4
Last Post: 12-17-2007, 11:38 AM
-
By nimmow in forum Database
Replies: 1
Last Post: 02-11-2006, 06:42 PM
-
By lightningtechie in forum Database
Replies: 1
Last Post: 02-07-2006, 08:34 AM
-
By Steve in forum Database
Replies: 0
Last Post: 03-01-2002, 12:07 PM
-
By Dave in forum VB Classic
Replies: 3
Last Post: 05-25-2001, 02:32 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks