使用DISTINCT进行查询需要很长时间 [英] Query taking long time with DISTINCT

查看:377
本文介绍了使用DISTINCT进行查询需要很长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Access2003.项目中的一种表单需要很长时间才能显示给用户.

I'm using Microsoft Access 2003. One form in my project takes a long time to appear to users.

这是适用的查询:

SELECT DISTINCT tb_KonzeptDaten.DFCC
,tb_KonzeptDaten.OBD_Code AS Konzept_Obd
,tb_bauteile.*
,FehlerCodes_akt_Liste.VAG_Code
,FehlerCodes_akt_Liste.OBD_Code
,FehlerCodes_akt_Liste.F_Klasse_EU
,FehlerCodes_akt_Liste.F_Klasse_US
,FehlerCodes_akt_Liste.CDT AS CdtNr
,FehlerCodes_akt_Liste.Pfad_Bezeichnung
,FehlerCodes_akt_Liste.Fehlerpfad AS PfadName
,FehlerCodes_akt_Liste.Fehlerunterpfad
,tb_bauteile_Tools.Tool AS Tool_
FROM (
    (
        tb_bauteile LEFT JOIN FehlerCodes_akt_Liste ON tb_bauteile.OBD2_Plaus = FehlerCodes_akt_Liste.ID
        ) LEFT JOIN tb_bauteile_Tools ON tb_bauteile.Tool = tb_bauteile_Tools.ID
    )
LEFT JOIN tb_KonzeptDaten ON FehlerCodes_akt_Liste.Fehlerpfad = tb_KonzeptDaten.DFC;

如果我删除 DISTINCT ,然后运行查询,性能将会得到改善 (从9秒到2秒).此外,我还在必要的字段上添加了索引.

If I delete DISTINCT and then run the query, the performance will be improved (from 9 seconds to 2 seconds). In addition, I put an index on the neccessary fields as well.

如何更改查询(可能没有DISTINCT)以提高性能?

How can I change my query(maybe without DISTINCT) to improve the performance?

推荐答案

我建议您获取不同的ID,然后在列查询中获取所需的列.

I will suggest get distinct ids and then in column query get your desired columns.

类似的东西

Select (select Fehlerpfad from FehlerCodes_akt_Liste where id=A.id ) as col1, ...
from
(
   Select distinct ids from table
   .........
) A

这篇关于使用DISTINCT进行查询需要很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆