分享

表的连接与查询

 weixiaofeng01 2017-03-10
表的连接:
 外链接:
 ——左连接:left [outer] join
 ——右连接:right [outer] join 
  ——全连接:full [outer] join 
  同样也可以使用'+'来表示,只适用于左右连接,有‘+’的一方是连接方
  内连接:
  在数据库操作中,不同表之间可以通过相同类型的列,进行关联查询,
例子: 
  select*from book left outer outer join
 borrow on book.bid=borrow.bid;
 

 
 select bname,sname from book,borrow,student
 where borrow.bid=book.bid
 and
 borrow.sid=student.sid
 and
 book.bname =|in 'java';当只有一本叫java的书的时候用=,有多本时用in
题目:
1、根据书的id查询借书人的名字
2、根据书的id查询借书人的年龄
3、根据借书人的id查询借的书籍
 题1思路:
 1.bid=1,
 2.borrow查bid=1的人的sid;
 3.从student表中查询sid对应的sname
 select sname ,sage from student where 
 sid=(
 select sid from borrow where bid =1
 )
 题目3:
 select bname from book where 
 bid=(
 select bid from borrow where
 sid=(
  select sid from student where sid=1001
 )
 );












    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多