Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Simple Question for a Oracle/SQL Guru
I haven't been able to test this but it should work...
Select A.Patient_no, A.Appointment.Sv_date, B.Appointment.Sv_date
from Appointment A, Appointment B
where A.Patient_no = B.Patient_no and
A.D_name ='Miss Brown' and B.D_name ='Mr Hussein' and A.Sv_date between to_date('01-AUG-99') and to_date('30-SEP-99') and B.Sv_date between to_date('01-AUG-99') and to_date('30-SEP-99');
Better would be
Select C.Patient_Name as Patient, A.D_name as Dentist1, A.Appointment.Sv_date as Appointment1, B.D_name as Dentist2, B.Appointment.Sv_date as Appointment2,from Appointment A, Appointment B, Patient C where A.Patient_no = B.Patient_no and
A.Patient_no = C.Patient_no and A.D_name ='Miss Brown' and B.D_name ='Mr Hussein' and A.Sv_date between to_date('01-AUG-99') and to_date('30-SEP-99') and B.Sv_date between to_date('01-AUG-99') and to_date('30-SEP-99'); If you don't want to specify the dentists' names you could replace A.D_name ='Miss Brown' and B.D_name ='Mr Hussein' and with A.D_name <> B.D_name and
for more fun stuff get Celko's book 'SQL for Smarties'
Jaswinder Suri <Jaswinder.Suri_at_msdw.com> wrote in message news:384E244E.C79D9B37_at_msdw.com...
I am a novice at writing SQL commands to manipulate an Oracle database and
am having difficulty combining the following Select statements that
determine -
Which patients
were seen by two Dentist during the months of August and September.
Select 1
Select Appointment.Patient_no, Patient.Patient_no, Appointment.Sv_date
from Appointment, Patient
where Appointment.Patient_no = Patient.Patient_no and
Appointment.D_name ='Miss Brown' and Appointment.Sv_date Between to_date('01-AUG-99') and
to_date('30-SEP-99');
Which returned the following result
Patie Patie Sv_Date
----- ----- ---------
Appointment.D_name ='Mr Hussein' and Appointment.Sv_date Between to_date('01-AUG-99') and
to_date('30-SEP-99');
Which returned the following result
Patie Patie Sv_Date
----- ----- ---------
f4221 f4221 21-AUG-99
4 Appointment.D_name ='Mr Hussein' and 5 Appointment.Sv_date Between to_date('01-AUG-99') and 6 to_date('30-SEP-99') IN 7 (Select Appointment.Patient_no, Patient.Patient_no, Appointment.Sv_date 8 from Appointment, Patient 9 where Appointment.Patient_no = Patient.Patient_no and 10 Appointment.D_name ='Miss Brown' and 11 Appointment.Sv_date Between to_date('01-AUG-99') and
to_date('30-SEP-99'));
I keep getting an Error at line 6
IN *