zoukankan      html  css  js  c++  java
  • mysql自关联和多表连接查询

    自关联操作       
     多表连接查询  inner  join 内查询   left  join  左查询   right  join  右查询 
                                                                                                           
     select student.id,student.name,classes.name from student inner join classes on student.cls_id = classes.id;                                                                
      inner join内连 left join左连 right join右连     表名join 表名 on 连接字段        
                          
     select student.name,course_student.cid from student left join course_student on student.id = course_student.sid;                                                            
      以student.id与course_student.sid连接匹配,打印student.name,course_student.cid         
                           
        select student.name,course.name from student left join course_student on student.id = course_student.sid left join course on course_student.cid =course.id;                                                                    三表(2明细表+1关系表)相连取交集打印学生名字与课程名字       
                           
    select * from areas as p inner join areas as a on p.aid = a.pid where p.atitle = '河南省';                                                                
          省、市,两表查询在一张表里(as起别名)用上级id打印,                                    
     
     select * from areas as p inner join areas as c on c.pid = p.aid inner join areas as a on a.pid = c.aid where a.atitle = '二七区';                                                            
          省、市、区,三表查询在一张表里(as起别名)用上级id打印区表title为‘二七区’的数据     
     
    select * from from areas as p inner join areas as c on c.pid = p.aid inner join areas as  as a on a.pid = c.aid where p.atitle = '河南省';     
      打印河南省所有的市和所有的区
     
  • 相关阅读:
    vscode sftp 本地目录设置问题
    Zend where or怎么传
    docker如何查看最近创建的容器
    基于apline构建php7+nginx
    修改layui tree组件支持上移下移
    mysql千万级数据表如何删除
    filezilla 链接ftp不显示本地目录 “您没有权限列出该目录内容”
    php使用socket通过tcp通信及php16进制求和校验位计算
    Session must be started before any output has been sent to the browser;问题解决
    mysql数据库中的union和union的区别(示例演示)
  • 原文地址:https://www.cnblogs.com/sunzhiqi/p/10072700.html
Copyright © 2011-2022 走看看