数据库
首页 > 数据库> > Mysql03_select_2

Mysql03_select_2

作者:互联网

内容接Mysql02_selece_1点击跳转Mysql02_select_1


11、连接查询

字段1 字段2 字段3 字段4
stu stno name class card
sco id couno stno sco
cou couno name
  1. 两表连接

    • 等值连接

      select *from stu,sco where stu.stno = sco.stno
      
    • 内连接

      select *from stu inner join sco on tu.stno=sco.stno
      
  2. 三表连接

    • 等值
    select *from stu,sco where stu.stno = sco.stno 
    and sco.couno=cou.couno
    
    • 内连接
    select *from stu inner join sco on stu.stno=sco.stno
    inner join cou on
    sco.couno=cou.couno
    
  3. 左连接/右连接

    • left join 左表全部显示
    • right join 右表全部显示


12 、自关联

数据库准备(areas)

adi atitle pid
1 asheng NULL
2 ashi 1
3 bsheng NULL
4 bshi 3
  1. 查询'asheng'下的shi
select *from areas as Sheng,areas as Shi
where Sheng.aid = Shi.pid
and Sheng.atitle = 'asheng'
  1. 查询'ashi下的qu
select *from areas as Shi,areas as qu
where Shi.aid = qu.pid
and Shi.atitle = 'ashi'
  1. 查询'asheng'下的qu(三级)
select Sheng.atitle,qu.atitle
from 
areas as Sheng,areas as Shi,areas as qu
where 
Sheng.aid=Shi.pid and Shi.aid=qu.pid

13、子查询

子查询关键字 in

14、数据分表

标签:sco,Mysql03,stno,stu,Shi,where,select
来源: https://www.cnblogs.com/zhouDEblogs/p/14408528.html