二、等值与非等值连接查询 等值连接、自然连接、非等值连接 [例32]査询每个学生及其选修课程的情况。 select Student * SC x FROM Student SC WHERE Student sno SC Sno: An Introduction to Database System
An Introduction to Database System 二、等值与非等值连接查询 等值连接、自然连接、非等值连接 [例32] 查询每个学生及其选修课程的情况。 SELECT Student.*,SC.* FROM Student,SC WHERE Student.Sno = SC.Sno;
等值连接 连接运算符为=的连接操作 [<表名1>]<列名1>=[<表名2>]<列名2> 任何子句中引用表1和表2中同名属性时,都必须加 表名前缀。引用唯一属性名时可以加也可以省略表 名前缀 An Introduction to Database System
An Introduction to Database System 等值连接 ◼ 连接运算符为 = 的连接操作 ◼ [<表名1>.]<列名1> = [<表名2>.]<列名2> ◼ 任何子句中引用表1和表2中同名属性时,都必须加 表名前缀。引用唯一属性名时可以加也可以省略表 名前缀
等值连接 假设 Student表、SC表分别有下列数据: Student表 SI no Sname Ssex Sage Sdept 95001李勇男20 CS 95002刘晨女19 95003王敏女18 MA 95004张立男19 An Introduction to Database System
An Introduction to Database System 等值连接 假设Student表、SC表分别有下列数据: Student表 Sno Sname Ssex Sage Sdept 95001 李勇 男 20 CS 95002 刘晨 女 19 IS 95003 王敏 女 18 MA 95004 张立 男 19 IS
等值连接 SC表 S no Cno Grade 95001 9 95001 85 95001 95002 2323 88 90 95002 80 An Introduction to Database System
An Introduction to Database System 等值连接 SC表 Sno Cno Grade 95001 1 92 95001 2 85 95001 95002 95002 3 2 3 88 90 80
等值连接 结果表 Student Sno Sname Ssex Sage Sdept SCSno Cno Grade 95001 李勇 20 95001 92 95001 李勇 20 CS 95001 85 95001 李勇 男男男 20 Cs95001 88 95002 刘晨女19 95002 12323 90 95002 刘晨女19 IS 95002 80 An Introduction to Database System
An Introduction to Database System 等值连接 结果表 Student.Sno Sname Ssex Sage Sdept SC.Sno Cno Grade 95001 李勇 男 20 CS 95001 1 92 95001 李勇 男 20 CS 95001 2 85 95001 李勇 男 20 CS 95001 3 88 95002 刘晨 女 19 IS 95002 2 90 95002 刘晨 女 19 IS 95002 3 80