表连接

--表连接
select Students .Name ,Students .Age,Classes .Name from Students
join Classes on Students .CId =Classes .Id

--查询年龄大于3的学生
select Students .Name ,Students .Age ,Classes .Name from Students
join Classes on Students .CId =Classes .Id where Students .Age >3
--left join 会把左边的表的数据全部查出来
select Students .Name ,Students .Age ,Students .Birthday,classes.Name from Students
left join Classes on Students .CId =Classes .Id

--right join 首先满足右表的数据,如果连接条件满足就显示左表的数据,如果不满足就显示null
select Students .Name ,Students .Age ,Students .Birthday,classes.Name from Students
right join Classes on Students .CId =Classes .Id

posted @ 2014-04-06 22:47  编程猴子  阅读(128)  评论(0编辑  收藏  举报