用两个表(a_table.b_table),关联字段a_table.a_id和b_table.b_id来演示一下MySQL的内连接.外连接( 左(外)连接.右(外)连接.全(外)连接). MySQL版本:Server version: 5.6.31 MySQL Community Server (GPL) 数据库表:a_table.b_table 主题:内连接.左连接(左外连接).右连接(右外连接).全连接(全外连接) 表为: 内连接: 1. 交叉连接查询(基本不会使用-得到的是两个表的乘积)…
elect ename,job,sal from emp where deptno>10 order by sal desc; 联合查询,PK dept.deptno FK emp.deptno select emp.ename,dept.dname,dept.deptno from emp join dept on emp.deptno = dept.deptno; 也可以指定别名: select e.ename,d.dname,d.deptno from emp e join dept…
交叉连接(cross join):该连接产生的结果集笛卡尔积 a有7行,b有8行 a的第一行与b的每一行进行连接,就有8条a得第一行 7*8=56条 select a.real_name,s.unix_host,s.os_username from account a cross join service s:(56条) select a.real_name,s.unix_host,s.os_username from account a cross join service s wh…
1.左连接 select a.filed1,a.filed2,b.filed1 from a (左表) left join b(右表) on a.commonfiled = b.commonfiled 查询思路:按照匹配字段(外键),b表记录与a表记录进行逐一匹配,若有n条匹配,则形成n行.若无匹配,则左表中得记录是全的,即使右表没有匹配的字段存在 2.右连接 select a.filed1,a.filed2,b.filed1 from a (左表) right join b(右表) on a.…