[英]Query with UNION keyword runs very slow in mysql
Why is it that a query with UNION keyword runs very slow in mysql? 为什么带有UNION关键字的查询在mysql中运行非常慢?
I have created a query using UNION keyword but everytime I execute it, it takes a long time before the output was displayed. 我已经使用UNION关键字创建了一个查询,但是每次执行它时,显示输出都需要很长时间。
This is the query I used. 这是我使用的查询。
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;
Is there any possible way that can help on how to run this query faster. 有什么可能的方法可以帮助您更快地运行此查询。
Thanks in advance. 提前致谢。
Try this 尝试这个
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 tbldirtraining
WHERE emp_id = '6555'
AND cert_date <> ''
ORDER BY cert_date desc,sptrain_from asc;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.