DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2009
    Posts
    5

    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?

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    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

  3. #3
    Join Date
    May 2009
    Posts
    5
    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

  4. #4
    Join Date
    Oct 2008
    Posts
    141

    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

  1. Union query
    By peljo in forum Database
    Replies: 4
    Last Post: 12-17-2007, 11:38 AM
  2. Tough SQL query / procedure needed
    By nimmow in forum Database
    Replies: 1
    Last Post: 02-11-2006, 06:42 PM
  3. SQL2000 remote SQL query
    By lightningtechie in forum Database
    Replies: 1
    Last Post: 02-07-2006, 08:34 AM
  4. DTS Data Driven Query examples needed
    By Steve in forum Database
    Replies: 0
    Last Post: 03-01-2002, 12:07 PM
  5. SQL help needed (count query with two tables)
    By Dave in forum VB Classic
    Replies: 3
    Last Post: 05-25-2001, 02:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links