数据库各种语句相关

数据库迁移校验 https://ceshiren.com/t/topic/24710
数据库的实时更新 https://ceshiren.com/t/topic/26750

1.数据库中的连接方式

https://www.cnblogs.com/hungryquiter/p/17003716.html
数据库中连接方式分类:
(1)内连接: 也叫等值连接,即为求两个表的交集,关键字inner join

-- join
select * from course c join teacher t ON c.t_id = t.t_id 
-- inner join
select * from course c inner join teacher t on c.t_id = t.t_id 
-- 逗号的连表方式就是内连接
select * from course c ,  teacher t where c.t_id = t.t_id 

(2)外连接:

  • 左连接:从左表取出全部记录,与右表匹配(没有匹配的,以null值代表右边表值),关键字left join
  • 右连接:从右表取出全部记录,与右表匹配(没有匹配的,以null值代表左边表值),关键字right join
-- left join
select * from course c left join teacher t  on  c.t_id = t.t_id 
  • 全连接:关键字 full join(mysql暂时不支持,但可以使用union将两个结果集“堆一起”,利用左连接,右连接分两次将数据取出,然后用union将数据合并去重。)
-- oracle的全连接
select * from a full join b on a.id = b.id

-- mysql的全连接
-- mysql中没有full join,mysql可以使用union实现全连接;
select * from a left join b on a.id = b.id
union
select * from a right join b on a.id = b.id