The question states: "Find Name of patients who have been treated by Dr Brian or who have had an Extended Consultation.
The following is the relational schema for the database:
Patient (PatientID, FamilyName, GivenName)
Doctor (ProviderNo, Name)
Item (ItemNo, Description, Fee)
Account (AccountNo, ProviderNo, PatientID, Date)
AccountLine (AccountNo, ItemNo)
Where:
- Description Contains the value "Extended Consultation" among other values.
- ProviderNo is unique number for each doctor.
As only attributes from the patient table are used i gather you only need to do a subquery using an "ANY" statement to outline the condition, where only one needs to be true.
So i tired this query:
Expand|Select|Wrap|Line Numbers
- Select familyname, givenname
- from dtoohey.Patient
- where patient.patientID in (select patientID
- from dtoohey.account
- where account.providerNo any (select providerNO
- from dtoohey.doctor
- where doctor.name = 'Dr Brian'
- and account.accountno any (select accountNo
- from dtoohey.accountline
- where accountline.itemNo In (select itemNo
- from dtoohey.item
- where description = 'Extended Consultation'))));
Error at Command Line:5 Column:50
Error report:
SQL Error: ORA-00920: invalid relational operator
00920. 00000 - "invalid relational operator"
It also comes up with an error message for the second relational operator.
This statement works fine with IN however i dont think that producers the right result.
Althought i am still learning sql, if there is a better structured query comapred to this one please let me know, or how to remove the syntax error. Thanks:)