Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help

Author  Topic 

okuth0r
Starting Member

1 Post

Posted - 2013-06-30 : 16:16:07
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)

17689 Posts

Posted - 2013-06-30 : 22:35:55
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
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-07-01 : 00:38:17
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

52326 Posts

Posted - 2013-07-01 : 01:25:41
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
   

- Advertisement -