left jion 左联结
right jion 右联结
inner jion 等值联结
create table teacher(
tid int(5) primary key auto_increment,
tname varchar(100) not null,
age int,
phone char(11)
)engine=INNODB /*插入信息*/
insert into teacher(tname,age,phone) values('张三',54,''); /* 哪些老师带课了*/
select distinct(t.tname) ,t.age
from teacher t inner join course c
on t.tid=c.tid ; /*哪些老师没有代课*/
select t.tname,t.age,c.cname
from teacher t left join course c
on t.tid=c.tid
where c.cname is null ;
以上完整性不足,往后补上....
这里写的不错,转载:https://www.cnblogs.com/pcjim/articles/799302.html