“各种连接(等值连接、内连接、外连接、左连接、右连接、全连接)”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
第1行: 第1行:
 +
=== 演示数据 ===
 +
 +
==== 学生表和学生数据 ====
 
<syntaxhighlight lang="sql">
 
<syntaxhighlight lang="sql">
 
CREATE TABLE `student` (
 
CREATE TABLE `student` (
第9行: 第12行:
 
   UNIQUE KEY `student_num` (`sid`)
 
   UNIQUE KEY `student_num` (`sid`)
 
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 +
 +
INSERT INTO `sql`.`student`
 +
(`snum`,
 +
`sname`,
 +
`sage`,
 +
`sclass`)
 +
VALUES
 +
(20201101,'张三',20,150),
 +
(20201102,'李四',18,151),
 +
(20201103,'王五',19,151),
 +
(20201104,'赵六',18,150),
 +
(20201105,'钱七',21,151),
 +
(20201106,'孙八',20,152);
  
 
</syntaxhighlight>等值连接/显式内连接
 
</syntaxhighlight>等值连接/显式内连接

2022年11月3日 (四) 08:00的版本

演示数据

学生表和学生数据

CREATE TABLE `student` (
  `sid` int(11) NOT NULL AUTO_INCREMENT,
  `snum` int(11) NOT NULL,
  `sname` varchar(20) NOT NULL,
  `sage` tinyint(4) DEFAULT NULL,
  `sclass` smallint(6) NOT NULL,
  PRIMARY KEY (`snum`),
  UNIQUE KEY `student_num` (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `sql`.`student`
(`snum`,
`sname`,
`sage`,
`sclass`)
VALUES
(20201101,'张三',20,150),
(20201102,'李四',18,151),
(20201103,'王五',19,151),
(20201104,'赵六',18,150),
(20201105,'钱七',21,151),
(20201106,'孙八',20,152);

等值连接/显式内连接

自然连接

外连接

内连接

全连接