不在访问查询 [英] Not In access query

查看:69
本文介绍了不在访问查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面有两个表

tblLoc(LocCode) tblData(Item,LocCode)

tblLoc(LocCode) tblData(Item,LocCode)

在tblData中,有额外的LocCode在tblLoc中找不到.

In tblData, there is extra LocCode that does not find in tblLoc.

SELECT D.LocCode
FROM tblData AS D
WHERE D.LocCode NOT IN (SELECT LocCode FROM tblLoc);

我使用此查询.太慢了有更好的查询吗?

I use this query. It's slow. Is there any better query?

推荐答案

在tblData和tblLoc之间的LocCode上使用左联接.将结果集限制为仅那些tblLoc LocCode为Null的行.如果您还没有索引,请在LocCode上为tblLoc添加一个索引.

Use a LEFT JOIN on LocCode between tblData and tblLoc. Restrict the result set to only those rows where tblLoc LocCode is Null. Add an index on LocCode for tblLoc, if you don't already have one.

SELECT d.LocCode
FROM
    tblData AS d
    LEFT JOIN tblLoc AS l
    ON d.LocCode = l.LocCode
WHERE l.LocCode Is Null;

这篇关于不在访问查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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