关于MYSQL的学习笔记--多表查询
内连接查询
1.隐式内连接查询(使用where条件消除无用数据)
select * from emp,dept where emp.'dept_id'=dept.'id';
--查询员工表的名称,性别,部门表的名称
select emp.name,emp.gender,dept.name from emp,dept where emp.'dept_id'=dept.'id';
--当数据库名过长时我们在查询的时候可以用别名来代替数据库名称
select
t1.name,t1.gender,t2.name
from
emp t1,dept t2
where
t1.'dept_id'=t2.'id';
2.显式内连接查询
语法:
select 字段列表 from 表名1 inner join 表名2 on 条件;
--例子
select * from emp inner join dept on emp.'dept_id'=dept.'id'; --inner是可以省略的
select * from emp join dept on emp.'dept_id'=dept.'id';