Sql 左联接查询而不是不存在
我有一个“notexists查询”执行得很差。所以我认为“左连接查询”的性能会更好,但事实并非如此。我正在VBA中运行这些查询 这是我的“不存在查询”Sql 左联接查询而不是不存在,sql,left-join,max,not-exists,Sql,Left Join,Max,Not Exists,我有一个“notexists查询”执行得很差。所以我认为“左连接查询”的性能会更好,但事实并非如此。我正在VBA中运行这些查询 这是我的“不存在查询” 从MyTable中选择*作为t1 其中t1.ID_person=1960081947465 和t1.ID_公司68550 t1.FullTime+26.3>=37.33 t1.日期=37.33 t2.日期=37.33 t2.日期=37.33 和t1.Date我想说的是,对于参与join/where子句的所有列,您需要按照它们在where子句中出现
从MyTable中选择*作为t1
其中t1.ID_person=1960081947465
和t1.ID_公司68550
t1.FullTime+26.3>=37.33
t1.日期=37.33
t2.日期=37.33
t2.日期=37.33
和t1.Date我想说的是,对于参与join/where子句的所有列,您需要按照它们在where
子句中出现的相同顺序建立索引。确保您有相应的索引,并且不存在
和连接
应执行类似且快速的操作。这是哪种RDBMS<代码>左连接。。。其中null在MySQL中的性能通常更好,而不存在在其他一些RDBMS(如Oracle和SQLServer)中的性能通常更好。Aaron Bertrand(仅限Sql Server)对此的强制性阅读:。它是Jet,我从vba/accessYes运行查询。我在where子句中的所有列上都有索引。但正如前面提到的,我离开join的方式没有使用索引。
SELECT * FROM MyTable AS t1
WHERE t1.ID_person = 1960081947465
and t1.ID_company <> 68550
and t1.FullTime + 26.3 >= 37.33
and t1.Date <= 20130101
and t1.Code not in (31,28)
and t1.FullTime < 100
and not exists (
select * from MyTable t2 where
t1.ID_person = t2.ID_person
and t2.ID_company <> 68550
and t2.FullTime + 26.3 >= 37.33
and t2.Date <= 20130101
and t2.Code not in (31,28)
and t1.Date< t2.Date
)
SELECT * FROM MyTable AS t1
LEFT JOIN
(
select * from MyTable t2 where
and t2.ID_company <> 68550
and t2.FullTime + 26.3 >= 37.33
and t2.Date <= 20130101
and t2.Code not in (31,28)
) subq
ON t1.ID_person = subq.ID_person and t1.Date < subq.Date
WHERE t1.ID_person = 1960081947465
and t1.ID_company <> 68550
and t1.FullTime + 26.3 >= 37.33
and t1.Date <= 20130101
and t1.Code not in (31,28)
and t1.FullTime < 100
and subq.ID_person IS NULL