Oracle SQL 语法:内部联接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5968222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle SQL Syntax: Inner Join
提问by Will
I don't have access to an Oracle Database right now, so I'm posting my question here:
我现在无法访问 Oracle 数据库,所以我在这里发布我的问题:
Is the following statement valid Oracle SQL Syntax?
以下语句是否有效的 Oracle SQL 语法?
SELECT a1
FROM t1 INNER JOIN t2
I'm particularly wondering whether we need to specify a join attribute for the inner join.
我特别想知道我们是否需要为内连接指定一个连接属性。
Best, Will
最好的,威尔
回答by Conrad Frix
You're missing ON
你不见了 ON
Like
喜欢
SELECT a1
FROM t1 INNER JOIN t2
ON t1.SomeID = t2.SomeID
回答by APC
So, this is the query you're thinking of....
所以,这是您正在考虑的查询....
SQL> select e.ename
2 , d.dname
3 from emp e inner join dept d
4 /
from emp e inner join dept d
*
ERROR at line 3:
ORA-00905: missing keyword
SQL>
As we can see, it fails. The INNER JOIN syntax demands that we provide columns to join on ...
正如我们所见,它失败了。INNER JOIN 语法要求我们提供用于连接的列...
SQL> select e.ename
2 , d.dname
3 from emp e inner join dept d
4 on ( d.deptno = e.deptno )
5 /
ENAME DNAME
---------- --------------
SCHNEIDER ACCOUNTING
BOEHMER ACCOUNTING
KISHORE ACCOUNTING
ROBERTSON RESEARCH
...
FEUERSTEIN HOUSEKEEPING
PODER HOUSEKEEPING
TRICHLER HOUSEKEEPING
21 rows selected.
SQL>
There is an alternative syntax, the NATURAL JOIN. This syntax will automatically join the two tables on the basis of all columns which share the same name.
有一种替代语法,NATURAL JOIN。此语法将根据共享相同名称的所有列自动连接两个表。
SQL> select e.ename
2 , d.dname
3 from emp e natural join dept d
4 /
ENAME DNAME
---------- --------------
SCHNEIDER ACCOUNTING
BOEHMER ACCOUNTING
KISHORE ACCOUNTING
ROBERTSON RESEARCH
...
FEUERSTEIN HOUSEKEEPING
PODER HOUSEKEEPING
TRICHLER HOUSEKEEPING
21 rows selected.
SQL>
This is a neat trick but really shouldn't be relied upon in production code; it is a bug waiting to happen.
这是一个巧妙的技巧,但在生产代码中真的不应该依赖;这是一个等待发生的错误。
回答by cmutt78
You will need to add an ON clause
您将需要添加一个 ON 子句
SELECT a1
FROM t1 INNER JOIN t2 on t1.a1=t2.a1
回答by Olaf
Yes, you have to specify join condition:
是的,您必须指定加入条件:
FROM t1 INNER JOIN t2 on t1.f = t2.f
从 t1 INNER JOIN t2 on t1.f = t2.f