当前位置:Gxlcms > 数据库问题 > mysql自关联

mysql自关联

时间:2021-07-01 10:21:17 帮助过:21人阅读

         多表连接查询 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 = ‘河南省‘;        打印河南省所有的市和所有的区  

mysql自关联

标签:nbsp   HERE   mysql   sele   数据   course   left join   span   mys   

人气教程排行