当B表很大时用exist
效率会要高很多
EXISTS用于检查子查询是否至少会返回一行数据,该子查询实际上并不返回任何数据,而是返回值True或False.
结论:IN()适合B表比A表数据小的情况
结论:EXISTS()适合B表比A表数据大的情况
select * from student
where exists (select sc.sid from sc where student.sid = sc.sid);
select * from student
where student.sid in (select sc.sid from sc);
网友评论