[Solved] Nested SQL statements for Oracle [closed]


You don’t need to nest. You need to join.

You’ll probably need something like this, although I would need the exact table structure to be sure. But you’ll get the general idea.

select
  b.TITLE,
  a.LASTNAME,
  i.UNITSONHAND
from
  BOOK b
  inner join AUTHOR a on a.AUTHORID = b.AUTHORID
  inner join INVENTORY i on i.BOOKID = b.BOOKID
  inner join BRANCH br on br.BRANCHID = b.BRANCHID
where
  br.BRANCHID = 4

Some people would argue that BRANCH should be the first table, because you’re filtering on that. You can do that if you like and if you think it makes more sense. In some circumstances, it may result in better performance, although generally the query optimizer takes care of it.

5

solved Nested SQL statements for Oracle [closed]