sql 求相交的行
In a day to day scenario, we do meet with requirements where we need to get the common result set from multiple tables. In order to achieve such requirements, SQL has provided a feature called Intersect. Intersection means common between two or more. Similar to its literal meaning SQL intersect provides the common result between multiple SELECT statements.
在日常情况下,我们确实满足了需要从多个表中获取通用结果集的要求。 为了达到这样的要求,SQL提供了一个称为Intersect的功能。 交集是指两个或多个之间共有。 与它的字面意思相似,SQL相交提供了多个SELECT语句之间的公共结果。
SQL相交 (SQL Intersect)
The SQL Intersect clause is used for combining two or more SELECT queries, but the result set will be the intersection of the queries. In common words, SQL Intersect will provide the common result between multiple SELECT statements.
SQL Intersect子句用于合并两个或多个SELECT查询,但结果集将是查询的交集。 换句话说,SQL Intersect将在多个SELECT语句之间提供相同的结果。
SQL相交的使用规则 (Rules for Usage of SQL Intersect)
- The queries should have the same number of columns as part of the select query. 查询应具有与选择查询相同的列数。
- The data type for the result sets should be the same. 结果集的数据类型应该相同。
- Intersect uses column position for combination and not column name. 相交使用列位置进行组合,而不使用列名称。
- The column in each select query must be in the same order. 每个选择查询中的列必须具有相同的顺序。