网站首页 文章专栏 MYSQL查询~ 存在一个表而不在另一个表中的数据

MYSQL查询~ 存在一个表而不在另一个表中的数据

编辑时间:2018-07-12 09:51:27 作者:苹果 浏览量:2059


    前言:查询在表A中存在,但表B中没有的查询语句


1.

select * from  B  where (select count(1) as num from A where A.id = B.uid) = 0  //查询速度最快


2.

select A.id from A left join B on A.id=B.uid where B.uid is null //左连接查找,查询速度稍慢与上一条


3.

select distinct A.id from  A where A.id not in (select uid from B) //not in 简单粗暴,但是属于慢查询,数据量很大不建议使用


    出自:何冰华个人网站

    地址:https://www.hebinghua.com/

    转载请注明出处


来说两句吧
最新评论