-- 等值连接 -- 语法 select 结果 from 表1 inner join 表2 on 连接条件 SELECT s.num,s.name,s.sex,g.name FROM student s INNER JOIN grade g ON s.num = g.id -- 写法二 SELECT s.num,s.name,s.sex,g.name FROM student s,grade g WHERE s.num = g.id
-- 非等值连接 CREATE TABLE score_level( NAME VARCHAR(1), lower_score INT, upper_score INT ) SELECT s.num,s.name,sl.name FROM student s INNER JOIN score_level sl ON s.score BETWEEN sl.lower_score AND sl.upper_score
-- 自连接 CREATE TABLE t_area( id INT, NAME VARCHAR(20), pid INT ) SELECT t1.id,t1.name,t2.id,t2.name FROM t_area t1 INNER JOIN t_area t2 ON t1.pid = t2.id
-- 左外连接(以左边的表为中心查询,无论条件是否满足都会将左边数据查询出来) -- 学号,姓名,性别,年级名次 SELECT s.num,s.name,s.sex,g.name FROM student s LEFT JOIN grade g ON s.grade = g.id
-- 右外连接 学号,姓名,性别,年级名次 SELECT s.num,s.name,s.sex,g.name FROM student s RIGHT JOIN grade g ON s.grade = g.id
-- 使用sqlyog客户端工具进行数据库备份数据
-- 在修改,删除数据前进行数据备份