如下:
EXPLAIN SELECT *
FROM sal50 a
WHERE NOT
EXISTS (
SELECT 1
FROM sal50
WHERE a.man_no = man_no AND a.ym > ym
)
ORDER BY `man_no` ASC
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY a ALL NULL NULL NULL NULL 34337 Using where; Using filesort
2 DEPENDENT SUBQUERY sal50 ref sal501,sal502 sal501 5 sysal.a.man_no 19 Using where; Using index
按照explain的说法,执行顺序是先2,再1,即先查询sal50,再查询a.
但看了exists的说法,是exists作为where条件时,先对where前的主查询(外表)进行查询,然后将主查询的结果一个一个带入exists的子查询进行查询
请问我哪里理解错误,谢谢?
------解决方案--------------------------------------------------------