mysql数据库外连接,内连接,自然连接

create table join_teacher(
id int primary key auto_increment,
t_name varchar(10) not null,
gender enum('male','female','secret') not null
)engine innodb character set utf8;
insert into join_teacher values
(1,'韩信','male'),
(2,'李白','male'),
(3,'韩非子','secret');

create table join_class(
id int primary key auto_increment,
c_name varchar(10) not null,
root int not nclass values
(1,'php0115',207),
(2,'php0115',207),
(3,'php0115',207);

create table join_day(
id int primary key auto_increment,
t_id int not null,
c_id int not null,
days tinyint not null,
begin_date date not null,
end_date  date not null
)engine innodb character set utf8;
insert into join_day values
(1,1,1,15,20130115,20130220),
(2,2,2,20,20130222,20130325),
(3,3,3,15,20130327,20130418);

tbl_left inner join tbl_right on 连接条件
inner join
select join_teacher.t_name,join_teacher.gender,join_day.begin_date,join_day.end_date
from join_teacher inner join join_day on
join_teacher.id=join_day.t_id;

select * from join_teacher inner join join_day on
join_teacher.id=join_day.t_id;

left outer join
select * from join_teacher left outer join join_day on
join_teacher.id=join_day.t_id;
join 连接查询:将多个表的记录连接起来

分类:内连接,外连接,自然连接
内连接:数据内部的连接,要求:连接的多个数据必须存在才能连接
外连接:如果负责连接的一个或多个数据不真实存在,则称之为外连接


select s.*,si.* from info_class as c left join info_student as s on c.id=s.class_id
left join info_student_info as si on s.id=si.id where c.class_name='php0331';

select child.* from hd_cate as parent left join hd_cate as child on child.pid=parent.id where parent.name='MySQL';

格式:
select * from table1
left join table2 on 条件
left join table3 on 条件
......
按列往后加信息ull
)engine innodb character set utf8;
insert into join_

posted @ 2015-09-21 22:49  书书书书书书  阅读(957)  评论(0编辑  收藏  举报