标签:nbsp 学生 int 题目 test arch 数据 class tab
题目:查询小尹老师底下所有的学生
create database test;
use test;
create table stu(
id bigint,
classID bigint,
name varchar(10)
);
create table class(
id bigint,
teacherID bigint
);
create table teacher(
id bigint,
name varchar(10)
);
insert into stu values(1,2,‘马哥‘);
insert into class values(1,2);
insert into teacher values(2,‘小尹‘);
update class set id = 1 where id = 2;
错误的 因为左外连接 尽量保存左表的数据 on的条件相当于没有
SELECT S.* FROM `stu` S LEFT JOIN class C on S.classID = C.id
LEFT JOIN teacher T on C.teacherID = T.id and T.name = "小尹";
正确的
SELECT S.* FROM `teacher` T LEFT JOIN class C on T.id = C.teacherID
LEFT JOIN stu S on S.classID = 2 and T.name = "小尹";
标签:nbsp 学生 int 题目 test arch 数据 class tab
原文地址:https://www.cnblogs.com/ykpkris/p/13086501.html