2.Linux 环境中还原数据库
进入mysql交互页面:
create database wt
Linux 操作界面:
mysql -uroot -p +要还原的数据库 < wt.sql脚本文件
例子:mysql -uroot -p wt < wt.sql
多表
笛卡尔积
消除笛卡尔积
3*3=9条数据
a=a b=b c=c
表1.id=表2.id 消除
实现多表查询
基本连接
基本格式
select * from a,b where a.id = b.id
内连接
table1 inner join table2 on +条件
用法和基本连接一模一样的
基本格式
select *
from a inner join b
on a.id = b.id
基本连接,内连接
得到的是两个表共有的数据
file:///E:/YoudaoNote/data/906624425@qq.com/77e9fdd976ba4062a96dcc01d814b7b1/_%5Dn_%299@%7Dapovn5gc086e31r.png
左连接
table1 left join table2 on +条件
特点:
以左表为主,得到左表所有的数据 + 与右表共有的数据
select *
from a left join b
on a.id = b.id
右连接
table1 right join table2 on +条件
特点:
以右表为主,得到右表所有的数据 + 与左表共有的数据
select *
from a right join b
on a.id = b.id
左表独有的数据
select *
from a left join b
on a.id = b.id
where b.id is null
右左表独有的数据
select *
from a left join b
on a.id = b.id
where a.id is null
联合 union
作用:把表 a 独有的数据和表 b 独有的数据查询出来
select *
from a left join b
on a.id = b.id
union
select *
from a right join b
on a.id = b.id
注意点
SELECT id,stu_name from students UNION SELECT id,t_name from teacher;
#用来合并两条select语句的结果,两条select语句字段数量要一致,并且数据类型也要一致