数据准备:单纯为了对比左联,右联,内联的区别所做的数据,不考虑业务逻辑
CREATE TABLE student(
sid INT PRIMARY KEY,
sname VARCHAR(10) NOT NULL,
sage INT(10),
scity VARCHAR(10)
)DEFAULT CHARSET='utf8';
CREATE TABLE scourse(
sid INT PRIMARY KEY,
cid INT(10),
cname VARCHAR(10)
)DEFAULT CHARSET='utf8';
INSERT INTO student (sid,sname,sage,scity)VALUES(1,'张三',14,'英国伦敦'),(2,'李四',15,'美国旧金山'),(3,'王五',16,NULL),(4,'赵六',NULL,'澳大利亚');
INSERT INTO scourse (sid,cid,cname)VALUES(1,1,'外国文学'),(2,2,NULL),(4,NULL,'中国历史'),(5,NULL,NULL),(6,7,'英国美学');
-- 左联
SELECT *
FROM student a
LEFT JOIN scourse b ON a.sid = b.si