下面列举了几种情况下,MySQL会创建临时表:
- 当执行GROUP BY操作时
SELECT owner, COUNT(*) FROM pet GROUP BY owner;
SELECT name, birth FROM pet ORDER BY birth;
SELECT name FROM pet WHERE species = 'dog' UNION SELECT name FROM pet WHERE species = 'cat'
SELECT description FROM products ORDER BY description;
SELECT pet.name, owner.name FROM pet JOIN owner ON pet.owner_id = owner.id
需要注意的是,当查询结束后,MySQL会自动删除临时表。