找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手

杭州十期——mysql 语句——三表

[复制链接]
方法一:三表隐藏内连接
格式:select  *  from   表1 , 表2 ,表3   where  表1.关联的字段=表3.关联字段  and   表2.关联字段=表3.表3字段
案例:select  *  from  student as a , course as b , sc  as  c where  a.stu_no=c.stu_no and b.c_no=c.c_no

方法二:三表普通内连接
格式:select  *  from  表1 INNER JOIN  表3   on   表1.关联的字段=表3.关联字段    inner join 表2  on   表2.关联字段=表3.表3字段
案例:select  *  from  student as a INNER JOIN  sc  as  c on a.stu_no=c.stu_no  inner join  course as  b  on    b.c_no=c.c_no

方法三:三表普通左连接
格式:select  *  from  表1   left   JOIN  表3   on   表1.关联的字段=表3.关联字段    left    join 表2  on   表2.关联字段=表3.表3字段
案例:select  *  from  student as a left JOIN  sc  as  c on a.stu_no=c.stu_no  left join  course as  b  on    b.c_no=c.c_no

方法四:三表普通右连接
格式:select  *  from  表1   right  JOIN  表3   on   表1.关联的字段=表3.关联字段    right    join 表2  on   表2.关联字段=表3.表3字段
案例:select  *  from  student as a   right JOIN  sc  as  c on a.stu_no=c.stu_no  right    join  course as  b  on    b.c_no=c.c_no

方法五:先合两表,在两表合并成一表与第三个表合并
案例:select  s.stu_no ,s.stu_name from ( select  a.stu_no ,stu_name,c_no  from  student a  ,sc c where  a.stu_no=c.stu_no )s  ,course  as b  where  s.c_no=b.c_no

分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册