多表联合查询
1. 环境准备:
备注:三个表中至少有一个字段相同(字段表内信息可不完全一致,顺序也不必相同),从而起到三个表格相连的作用
2. 多表联合查询方式:
语法格式:select 标记1.字段名,标记2.字段名,标记1.字段名,标记3.字段名from表名1 标记1 ,表名2标记2,表名3标记3 where 标记1.字段名=标记2.字段名 and 标记1.字段名=标记3.字段名;
MariaDB [dazhu]> select c.id,c.name,c.chengji,j.jingyan,x.xinzi,x.gongsi from chengjibiao c,jianlibiao j,xinzibiao x where c.id=j.id and c.id=x.id;
3.多表联合查询,同时为字段设置as别名:
语法格式:select 标记1.字段名,标记2.字段名 as 别名A,标记1.字段名 as 别名1,标记3.字段名 as 别名c from 表名1 标记1 ,表名2 标记2,表名3 标记3 where 标记1.字段名=标记2.字段名 and 标记1.字段名=标