[英]Inner join two tables
No. that's not always the case. 不,并非总是如此。 But it is what we usually do, it is the normative pattern.
但这是我们通常要做的,这是规范模式。 (A SQL
INNER JOIN
operation does not require that the predicate be an equality comparison. And it's not necessary that a comparison be made on PRIMARY KEY and/or FOREIGN KEY columns.) (SQL
INNER JOIN
操作不需要谓词是相等比较。并且不必在PRIMARY KEY和/或FOREIGN KEY列上进行比较。)
Again, that's the normative pattern, but it's not a requirement of INNER JOIN
. 同样,这是规范模式,但这不是
INNER JOIN
的要求。 If the intent is to perform a join on the primary key / foreign key relationship, then yes, the predicates would be equality comparison on all of the component columns of the keys. 如果目的是对主键/外键关系执行联接,那么可以,谓词将是对键的所有组件列进行相等比较。
The answer is no to both your questions. 答案是否定的 。
The ON
clause of a JOIN
operation may contain any expression that evaluates to a 1 or 0, or none. JOIN
操作的ON
子句可以包含任何计算结果为1或0或不包含任何表达式。
For example, you can write this. 例如,您可以编写此代码。
FROM t1
JOIN t2 ON INSTR(t1.name, t2.surname) > 0 AND t2.nationality = 'US'
or even more horrendous sorts of things. 甚至更可怕的事情。
Foreign keys help enforce constraints. 外键有助于强制执行约束。 And, under favorable circumstances the associated indexes accelerate the query.
并且,在有利的情况下,关联的索引会加速查询。 But JOIN clauses are not at all limited to using keys and indexes.
但是JOIN子句完全不限于使用键和索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.