SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

okuth0r
Starting Member

1 Posts

Posted - 06/30/2013 :  16:16:07  Show Profile  Reply with Quote
I am taking a sql class and am writing advanced queries from data based on a fictional hospital.
Person_T (table with personal info:PersonID, PersonName, PersonAddr, Phone, etc)
Patient_T (table with PatientID(PersonID), contact date, insureance, emergency contact, refering and admitting physician)
Physician_T (table with PhysicianID(PersonID), DEA nuber, pager, speciality)
CareCenter_T (table with work location, day nurse in charge(PersonID), night nurse in charge(PersonID))
Resident_T (table with RPatientID(PersonID), BedNO)

How do i get a list of patients and their physicians? both use PersonName in the end?
Can you
SELECT PersonName, PersonName
From Patient_T

Im a little lost. Any help Appreciated. Thank you.

khtan
In (Som, Ni, Yak)

Singapore
17682 Posts

Posted - 06/30/2013 :  22:35:55  Show Profile  Reply with Quote
quote:
Can you
SELECT PersonName, PersonName
From Patient_T

table Patient_T only contains the patient ID and other information but without the Name. To get the name, you will need to use INNER JOIN to join table Patient_T to table Person_T.

Give it a try and post your query here.


KH
Time is always against us

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 07/01/2013 :  00:38:17  Show Profile  Reply with Quote
Person_T (table with personal info:PersonID, PersonName, PersonAddr, Phone, etc)
Patient_T (table with PatientID(PersonID), contact date, insureance, emergency contact, refering and admitting physician)
Physician_T (table with PhysicianID(PersonID), DEA nuber, pager, speciality)
-- try this
SELECT DISTINCT pat.*, CASE WHEN pat.(refering and admitting physician ID ) = pht.PhysicianID THEN pt.PersonName END As PhysicianName
FROM Person_T pt
JOIN Patient_T pat ON pt.PersonID = pat.PatientID
JOIN Physician_T pht ON pt.PersonID = pht.PhysicianID

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 07/01/2013 :  01:25:41  Show Profile  Reply with Quote
Hmm
I am taking a sql class and am writing advanced queries from data

but your requirement doesnt seem like an advanced one.Sounds like a simple join to me

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000