MySQL DQL(二)

多表连接查询和子查询

        select s.* ,teacher_name
        from student_table s,teacher_table t,
        where s.java_teacher =t.teacher_id;

        select s.* ,teacher_name
        from student_table s,teacher_table t,
        where s.java_teacher =t.teacher_id and student_name is not null;
        
外连接(在连接条件的列名后增加括号包括起来的外链接符(+或*))
        
        select s.* ,teacher_name
        from student_table s,teacher_table t,
        --右外链接
        where s.java_teacher =t.teacher_id(*);
SQL99
  交叉连接cross join
              select s.*,teacher name
              from student_table s
              cross join teacher_table t;
              
  自然连接 natural join
              select s.*,teacher name
              from student_table s
              natural join teacher_table t;
 on子句连接 
               select s.*,teacher name
              from student_table s
              join teacher_table t
              on s.java_teacher=t.teacher_id;
              
              
左右全外连接 left[outer]join   right[outer]join    full[outer]join
            select s.*,teacher name
              from student_table s
              full join teacher_table t
              on s.java_teacher=t.teacher_id;
              
              select s.*,teacher name
              from student_table s
              left join teacher_table t
              on s.java_teacher=t.teacher_id;
              
              select s.*,teacher name
              from student_table s
              right join teacher_table t
              on s.java_teacher=t.teacher_id;
              
子查询:在查询语句中嵌套另一个查询,子查询支持多层嵌套,
·            eg:
                select*
                from (select * from student_table)t
                where t.java_teacher>1;
                
                select*
                from student_table
                where java_teacher>
                (select teacher_id
                from teacher_table
                where teacher_name='Hello world'
                );
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值