SQL 操作顺序 [英] SQL order of operations

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

问题描述

如果我运行以下 SQL 查询

If I run the following SQL query

SELECT * 
FROM A
LEFT JOIN B
ON A.foo=B.foo
WHERE A.date = "Yesterday"

WHERE 语句是在 JOIN 之前还是之后计算的?

Does the WHERE statement get evaluated before or after the JOIN?

如果之后,编写此语句的更好方法是什么,以便仅返回 "Yesterday" 中的 A 中的行连接到 B?

If after, what would be a better way to write this statement so that returns only rows in A from "Yesterday" are joined to B?

推荐答案

这取决于数据库.

在 SQL Server 上,运行:SET SHOWPLAN_ALL ON 然后运行查询,您将了解运行时会发生什么.

On SQL Server, run: SET SHOWPLAN_ALL ON then run the query, you will get an idea of what happens when it runs.

这篇关于SQL 操作顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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