Solved

list data from 2 tables

Posted on 2008-10-10
4
222 Views
Last Modified: 2012-05-05
i am a novice to sql and oracle express edition i am learning . i need to display patient 's number(pno) , patient name(pname) and drug name (dname) they have been prescribed to .

i have tried: select pno, pname from patient but it is only for a single table drug name (dname) should be associated
hospital-data.doc
0
Comment
Question by:evry2004
  • 2
  • 2
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22689791
can you show the 2 tables full structure? and the column that is the foreign key?
usually, this should be a 3-tables design:

TABLE: patient
p_no
p_name
comments
...


TABLE: drug
d_no
d_name
comments
...

TABLE: prescription
p_id
p_no  => patient.p_no
d_no  => drug.d_no
date_start
date_end
comments
...

0
 

Author Comment

by:evry2004
ID: 22694759
tables are attached
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22694884
prescription = dose :)

this will be the base SQL...
you might need to add more conditions...
select *
  from patient p
  join dose 
    on dose.pno = p.pno 
  join drug d
    on d.dno = dose.dno

Open in new window

0
 

Author Closing Comment

by:evry2004
ID: 31505150
thank you
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question