MySQL之left jion 、 right jion 和inner jion 的区别和使用方法

left jion   左联结

right jion 右联结

inner jion 等值联结

 

 1 create table teacher(
 2    tid  int(5) primary key auto_increment,
 3    tname varchar(100) not null,
 4    age  int,
 5    phone char(11)
 6 )engine=INNODB
 7 
 8 /*插入信息*/
 9 insert into teacher(tname,age,phone) values('张三',54,'18919900000');
10 
11 /* 哪些老师带课了*/
12  select distinct(t.tname) ,t.age
13  from teacher t inner join course c
14  on t.tid=c.tid  ;
15 
16 /*哪些老师没有代课*/
17     select t.tname,t.age,c.cname
18     from teacher t left join course c
19     on t.tid=c.tid
20     where c.cname is null  ;       

以上完整性不足,往后补上....

这里写的不错,转载:https://www.cnblogs.com/pcjim/articles/799302.html

posted on 2018-01-11 17:51  墨~影  阅读(759)  评论(0编辑  收藏  举报

导航