×

MYSQL教程

MySQL中exists和in的区别

timeduoduoba timeduoduoba 发表于2024-05-24 浏览7361 评论0
一、in关键字 确定给定的值是否与子查询或列表中的值相匹配。in在查询的时候,首先查询子查询的表,然后将内表和外表做一个笛卡尔积,然后按照条件进行筛选。所以相对内表比较小的时候,in的速度较快。 select * from A where id in (select id from B) #等价于 for select id from B:先执行; 子查询 for select id from A where A.id = B.id:再执行外面的查询; 执行过程:in是先查询内表【