Q:

Write a query in SQL to obtain the name of the physicians with department who are yet to be affiliated

0

 Write a query in SQL to obtain the name of the physicians with department who are yet to be affiliated.

 

Sample table: physician

employeeid |       name        |           position           |    ssn
------------+-------------------+------------------------------+-----------
          1 | John Dorian       | Staff Internist              | 111111111
          2 | Elliot Reid       | Attending Physician          | 222222222
          3 | Christopher Turk  | Surgical Attending Physician | 333333333
          4 | Percival Cox      | Senior Attending Physician   | 444444444
          5 | Bob Kelso         | Head Chief of Medicine       | 555555555
          6 | Todd Quinlan      | Surgical Attending Physician | 666666666
          7 | John Wen          | Surgical Attending Physician | 777777777
          8 | Keith Dudemeister | MD Resident                  | 888888888
          9 | Molly Clock       | Attending Psychiatrist       | 999999999
 physician | department | primaryaffiliation
-----------+------------+--------------------
         1 |          1 | t
         2 |          1 | t
         3 |          1 | f
         3 |          2 | t
         4 |          1 | t
         5 |          1 | t
         6 |          2 | t
         7 |          1 | f
         7 |          2 | t
         8 |          1 | t
         9 |          3 | t
 departmentid |       name       | head
--------------+------------------+------
            1 | General Medicine |    4
            2 | Surgery          |    7
            3 | Psychiatry       |    9

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

SELECT p.name AS "Physician",
       p.position,
       d.name AS "Department"
FROM physician p
JOIN affiliated_with a ON a.physician=p.employeeid
JOIN department d ON a.department=d.departmentid
WHERE primaryaffiliation='false';

Sample Output:
    Physician     |           position           |    Department
------------------+------------------------------+------------------
 Christopher Turk | Surgical Attending Physician | General Medicine
 John Wen         | Surgical Attending Physician | General Medicine
(2 rows)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now