等值连接查询

Exisi 2023-02-28 16:04:02
Categories: Tags:
  • 等值连接等价于 [INNER] JOIN 内连接, 返回两个表中联结字段相等的行,即得到的结果是两张表的交集

语法

SELECT a.<col_name_a>, b.<col_name_b> ...

FROM  <tbl_name_a> AS a, <tbl_name_b> AS b

WHERE a.col_name  = b.col_name;

 

参数

说明

<col_name_a>

<col_name_b>

数据列名

<tbl_name_a>

<tbl_name_b>

数据表名

示例

SELECT  studentNo, studentResult

 

FROM student AS s, result AS r

 

WHERE s.studentNo = r.studentNo

 

运行结果如下:

studentNo

studentResult

112392

90

 

 

 

非等值连接

非等值连接与等值连接不同的是,连接条件的关系是非等量关系

语法

SELECT a.<col_name_a>, b.<col_name_b> ...

FROM  <tbl_name_a> AS a, <tbl_name_b> AS b

WHERE where_condition;

示例

SELECT  studentNo, studentResult

FROM student AS s, result AS r

WHERE r.studentResult BETWEEN 90 AND 80;

 

运行结果如下:

studentNo

studentResult

123194

95