Home >Database >Mysql Tutorial >How efficient is mysql's use of subqueries?
mysql subquery efficiency: The efficiency of using subquery [SELECT id,`name` FROM customer where id IN(select DISTINCT(customerid) from searchaccount] is 10 times higher.
The efficiency impact of mysql using subqueries
is only the use of id:
explain SELECT * from customer where id in(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
Result:
Using subquery:
explain SELECT id,`name` FROM customer where id IN(select DISTINCT(customerid) from searchaccount WHERE kfuid=126 AND iskf=1) LIMIT 20
Result:
Without subquery Query to achieve the same effect:
explain select DISTINCT(customerid) as id,c.name from searchaccount s LEFT JOIN customer c on s.customerid=c.id WHERE s.kfuid=126 AND s.iskf=1 limit 20
The efficiency is 10 times the impact.
Related free learning recommendations: mysql tutorial(Video)
The above is the detailed content of How efficient is mysql's use of subqueries?. For more information, please follow other related articles on the PHP Chinese website!