![Query Design](https://istack.dev59.com/FxULQ.webp)
![Query result](https://istack.dev59.com/fuRDd.webp)
SELECT PUBLISHER.PUBLISHER_CODE, PUBLISHER.PUBLISHER_NAME, BOOK.TITLE, BOOK.TYPE, INVENTORY.BRANCH_NUM, BRANCH.BRANCH_NAME
FROM PUBLISHER INNER JOIN (BRANCH INNER JOIN (BOOK INNER JOIN INVENTORY ON BOOK.BOOK_CODE = INVENTORY.BOOK_CODE) ON BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM) ON PUBLISHER.PUBLISHER_CODE = BOOK.PUBLISHER_CODE
WHERE (((BOOK.TYPE)='FIC') AND ((BRANCH.BRANCH_NAME)='Henry on the Hill'))
ORDER BY PUBLISHER.PUBLISHER_NAME;
我认为 MS SQL 可能在 Oracle 中也适用,因此我尝试了一下:
SQL> SELECT PUBLISHER.PUBLISHER_CODE, PUBLISHER.PUBLISHER_NAME, BOOK.TITLE, BOOK.TYPE, INVENTORY.BRANCH_NUM, BRANCH.BRANCH_NAME
2 FROM PUBLISHER INNER JOIN (BRANCH INNER JOIN (BOOK INNER JOIN INVENTORY ON BOOK.BOOK_CODE = INVENTORY.BOOK_CODE) ON BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM) ON PUBLISHER.PUBLISHER_CODE = BOOK.PUBLISHER_CODE
3 WHERE (((BOOK.TYPE)='FIC') AND ((BRANCH.BRANCH_NAME)='Henry on the Hill'))
4 ORDER BY PUBLISHER.PUBLISHER_NAME;
no rows selected
很明显那并没有生效。所以,我在我的Oracle 11g中进行了剪切/粘贴/编辑操作,以下是代码:
SQL> SELECT PUBLISHER.PUBLISHER_CODE, PUBLISHER.PUBLISHER_NAME, BOOK.TITLE, BOOK.TYPE,
2 INVENTORY.BRANCH_NUM, BRANCH.BRANCH_NAME
3 FROM PUBLISHER
4 inner join BOOK ON PUBLISHER.PUBLISHER_CODE = BOOK.PUBLISHER_CODE
5 inner join INVENTORY on INVENTORY.BRANCH_NUM = BRANCH.BRANCH_NUM
6 inner join BRANCH on INVENTORY.BRANCH_NUM = BRANCH.BRANCH_NUM
7 where BOOK.BOOK_TYPE = 'FIC'
8 and BRANCH.BRANCH_NAME = 'Henry on the Hill';
inner join INVENTORY on INVENTORY.BRANCH_NUM = BRANCH.BRANCH_NUM
*
ERROR at line 5:
ORA-00904: "BRANCH"."BRANCH_NUM": invalid identifier
那么我为什么会得到这个错误: ERROR at line 5: ORA-00904: "BRANCH"."BRANCH_NUM": 无效的标识符
连接顺序有影响吗? 如您所见,我是按顺序从表到表进行连接的。
语法顺序有关系吗?例如:
inner join BRANCH on INVENTORY.BRANCH_NUM = BRANCH.BRANCH_NUM 还是 inner join BRANCH on BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM
这有关系吗?
Oracle SQL中的连接格式正确吗?顺序正确吗?
如果是,为什么它不能运行?
顺便说一句,这是一门在线课程,虽然讲师非常细心,但我从阅读其他人的帖子和提出自己的问题中学到了很多。谢谢大家!