中文名称 | 字段名 | 类型 | 长度 |
学号 | code | C | 4 |
姓名 | name | C | 8 |
中文名称 | 字段名 | 类型 | 长度 |
学号 | Student_code | C | 4 |
姓名 | Student_name | C | 8 |
分数 | score | N | 3 |
SQL>select code, name from A intersect select student_code,student_name from B; |
图1使用intersect操做符查询的结果 |
第二种方法: in子句
in子句能够在子查询中为where子句计算所得的值建立一个列表。这种方法与前一种方法有所不一样的是,前一种方法比较多列但只使用一个intersect就好了,而一个in子句用来比较两个子查询的一列,比较几列就要使用几个in子句。下面举例说明如何取得两个查询的交集。
仍以A和B两张数据表为例,在oracle中运行如下查询,图2显示了这个查询的结果:
数据库
SQL>select code,name from A where A.code in (select student_code from B) and A.name in (select student_name from B) order by A.code; |
图2使用in子句查询的结果 |