Q:

Write a query in SQL to find the name of the patients and the number of the room where they have to go for their treatment

0

 Write a query in SQL to find the name of the patients and the number of the room where they have to go for their treatment.

 

Sample table: patient

ssn    |       name        |      address       |  phone   | insuranceid | pcp
-----------+-------------------+--------------------+----------+-------------+-----
 100000001 | John Smith        | 42 Foobar Lane     | 555-0256 |    68476213 |   1
 100000002 | Grace Ritchie     | 37 Snafu Drive     | 555-0512 |    36546321 |   2
 100000003 | Random J. Patient | 101 Omgbbq Street  | 555-1204 |    65465421 |   2
 100000004 | Dennis Doe        | 1100 Foobaz Avenue | 555-2048 |    68421879 |   3
 appointmentid |  patient  | prepnurse | physician |    start_dt_time    |     end_dt_time     | examinationroom
---------------+-----------+-----------+-----------+---------------------+---------------------+-----------------
      13216584 | 100000001 |       101 |         1 | 2008-04-24 10:00:00 | 2008-04-24 11:00:00 | A
      26548913 | 100000002 |       101 |         2 | 2008-04-24 10:00:00 | 2008-04-24 11:00:00 | B
      36549879 | 100000001 |       102 |         1 | 2008-04-25 10:00:00 | 2008-04-25 11:00:00 | A
      46846589 | 100000004 |       103 |         4 | 2008-04-25 10:00:00 | 2008-04-25 11:00:00 | B
      59871321 | 100000004 |           |         4 | 2008-04-26 10:00:00 | 2008-04-26 11:00:00 | C
      69879231 | 100000003 |       103 |         2 | 2008-04-26 11:00:00 | 2008-04-26 12:00:00 | C
      76983231 | 100000001 |           |         3 | 2008-04-26 12:00:00 | 2008-04-26 13:00:00 | C
      86213939 | 100000004 |       102 |         9 | 2008-04-27 10:00:00 | 2008-04-21 11:00:00 | A
      93216548 | 100000002 |       101 |         2 | 2008-04-27 10:00:00 | 2008-04-27 11:00:00 | B

All Answers

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

SELECT p.name AS "Patient",
       a.examinationroom AS "Room No.",
       a.start_dt_time AS "Date and Time of appointment"
FROM patient p
JOIN appointment a ON p.ssn=a.patient;

Sample Output:

      Patient      | Room No. | Date and Time of appointment
-------------------+----------+------------------------------
 John Smith        | A        | 2008-04-24 10:00:00
 Grace Ritchie     | B        | 2008-04-24 10:00:00
 John Smith        | A        | 2008-04-25 10:00:00
 Dennis Doe        | B        | 2008-04-25 10:00:00
 Dennis Doe        | C        | 2008-04-26 10:00:00
 Random J. Patient | C        | 2008-04-26 11:00:00
 John Smith        | C        | 2008-04-26 12:00:00
 Dennis Doe        | A        | 2008-04-27 10:00:00
 Grace Ritchie     | B        | 2008-04-27 10:00:00
(9 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