The queries are close, but not quite the same.
Because of the FK = (sub-query), this can only return ONE row.
However, I'm sure that you have more than one doctor who is a dentist.
Therefore, you get... ORA-01427: single-row subquery returns more than one row
Changing your query to...
select distinct name from patient where id <strong>IN</strong> (
select patient_fk from appointment where doctor_fk <strong>IN</strong> (
select id from doctor where specialty_fk=(
select id from specialty where name='DENTIST'
))); should get you the results you desire.
You also may wish to add...
Order by Upper (Name)
after all of your parentheses.