基于其他关系从关系中选择
Selecting from relation based on other relation
给定关系 A(a,b,c) 和关系 B(a,d,e),使用投影在 'B' 中隔离 'a',就像这样 'B_=projection_{a}(B)', 有没有办法排除 'A' 中所有与 'B' 没有共同点的 'a' 的元组?
请注意,我只使用关系代数,而不是扩展版本。
is there a way to exclude all tupples in 'A', that does not have an 'a' in common with 'B'?
这是双重否定:"exclude ... not ..."。让我们把它变成积极的:
"Show all tuples in A
that do have an a
in common with B
."
也就是说,您需要元组的一个子集。这里重要的是 a
是两个关系之间唯一的共同属性名称。然后从 Natural Join.
开始
A ⋈ B
这将产生具有所有属性的结果 {a, b, c, d, e}
。还不是你想要的,所以你在正确的轨道上进行了投影。我将使用 Codd 的原始运算符 (π
)。有两种方法;这些是等价的:
A ⋈ (π{a}( B )) // take just {a} from B
π{a, b, c}( A ⋈ B ) // take {a, b, c} from the result of Join
这是一个常用的操作,所以在 "extended" 操作符集合中还有一个 shorthand,以避免这种投影,称为 (left) SemiJoin
A ⋉ B
也称为'Matching'。
给定关系 A(a,b,c) 和关系 B(a,d,e),使用投影在 'B' 中隔离 'a',就像这样 'B_=projection_{a}(B)', 有没有办法排除 'A' 中所有与 'B' 没有共同点的 'a' 的元组?
请注意,我只使用关系代数,而不是扩展版本。
is there a way to exclude all tupples in 'A', that does not have an 'a' in common with 'B'?
这是双重否定:"exclude ... not ..."。让我们把它变成积极的:
"Show all tuples in A
that do have an a
in common with B
."
也就是说,您需要元组的一个子集。这里重要的是 a
是两个关系之间唯一的共同属性名称。然后从 Natural Join.
A ⋈ B
这将产生具有所有属性的结果 {a, b, c, d, e}
。还不是你想要的,所以你在正确的轨道上进行了投影。我将使用 Codd 的原始运算符 (π
)。有两种方法;这些是等价的:
A ⋈ (π{a}( B )) // take just {a} from B
π{a, b, c}( A ⋈ B ) // take {a, b, c} from the result of Join
这是一个常用的操作,所以在 "extended" 操作符集合中还有一个 shorthand,以避免这种投影,称为 (left) SemiJoin
A ⋉ B
也称为'Matching'。