MySQL连接两张表的方法


1、内连接
select Name,Rating from movie m,ratings r on m.MovieId=r.MoiveId
使用内连接时,显示的是两个表中Id相匹配的记录,如果为null就不会显示
2、左连接
select Name,Rating from movie m left join ratings r on m.MovieId=r.MoiveId
使用左连接时,显示join左边的表的所有数据(不管两表是否匹配),对于不匹配的部分都用NULL显示
3、右连接
select Name,Rating from movie m right join ratings r on m.MovieId=r.MoiveId
使用右连接时,与左外连接相反,显示join右边的表的所有数据
网友评论