为什么使用 UNION 关键字的查询在 mysql 中运行速度很慢?
我使用 UNION 关键字创建了一个查询,但每次执行它时,都需要很长时间才能显示输出。
这是我使用的查询。
SELECT process_trained AS Training_Title,
org_party AS Organizing_Party,
duration AS Duration,
Concat(Date_format(sptrain_from, '%d-%b-%y'), " to ",
Date_format(sptrain_to, '%d-%b-%y'), "") AS SpecialTraining_Date,
trainor AS Trainor,
category AS Category,
training_type AS Training_Type,
train_id,
Date_format(cert_date, '%d-%b-%Y') AS Date_Certified,
Date_format(re_certdate, '%d-%b-%Y') AS Re_Certificaton,
remarks,
filename
FROM(SELECT *,
cert_date AS cdate
FROM tbldirtraining
UNION ALL
SELECT *,
sptrain_from
FROM tbldirtraining) jes
WHERE emp_id = '6555'
AND cdate <> ''
ORDER BY cdate;
是否有任何可能的方法可以帮助您更快地运行此查询。
提前致谢。