SQL INNER JOIN问题

发布于 2024-09-13 07:48:33 字数 215 浏览 11 评论 0原文

我正在创建一个查询,该查询将显示从 8 个表派生的记录的信息。最初编写查询的开发人员使用“where this equals this”和“this equals this”的组合来创建连接。

此后我更改了查询以使用 INNER JOINS。我想知道我的方法是否比使用 WHERE 运算符的组合更好。

根据良好实践的衡量标准,内部连接的组合是一个不错的选择,还是我应该采用不同的技术。

I'm creating a query that will display information for a record which is derived from 8 tables. The developer who originally wrote the query used a combination of 'where this equals this' AND 'this equals this' to create the joins.

I have since changed the query to use INNER JOINS. I wondered if my approach was better than utilising a combination of WHERE operators.

On a measure of good practice, is a combination of INNER JOINS a good option or should I be employing a different technique.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦归所梦 2024-09-20 07:48:33

从性能的角度来看,不会有任何差异...至少在 Sql-server / Oracle 等著名的 RDBMS 上没有...这些数据库引擎能够识别两种模式的含义相同,并使用相同的执行计划两者...

在我看来,两者都是同样好的实践,但是您应该保持一致性和适当的对齐...我在某个地方听说oracle开发人员通常使用where子句,而Sql-Server则使用内连接...不太好对此非常确定...到目前为止,大多数编码员都能够理解这两种类型的查询...

From performance point of view, there will not be any difference... atleast not on prominent RDBMS like Sql-server / Oracle... These Database Engine, are capable of identifying both the patterns means the same and use the same execution plan for both...

In my humble opinion both are equally good practice, but you should maintain consistency and proper alignment... Somewhere I heard that where clause are generally used by oracle developers, and inner join by Sql-Server... Not very much sure about that... By now most of the coders are capable of understanding both types of queries...

美胚控场 2024-09-20 07:48:33

我相信两者之间没有性能差异:

ANSI 风格
SELECT * FROM Table1 a JOIN TABLE2 b on a.id = b.id

旧样式
从表 1 a 、表 2 b 中选择 *
WHERE a.id = b.id

ANSI 风格更新、更易读、更漂亮,我确实更喜欢旧风格,尤其是在连接超过 4/5 个表时...也许因为我是 Oracle 开发人员正如o_O之前所说

I beleive that there is no performance difference between both :

ANSI Style
SELECT * FROM Table1 a JOIN TABLE2 b on a.id = b.id

Old Style
SELECT * FROM Table1 a , TABLE2 b
WHERE a.id = b.id

The ANSI style is newer and more readable and pretty, i do prefer the old style especially when it comes to join more than 4/5 Tables... maybe because im an Oracle Dev as it was said before o_O

メ斷腸人バ 2024-09-20 07:48:33

两者的行为都是一样的(正如国王所说)。就我个人而言,我更喜欢 INNER/OUTER/LEFT JOIN 语法,因为它更直观/明确。当您在 WHERE 子句中使用带有连接条件的 LEFT JOIN 时,您必须开始使用加号,然后您必须记住将它们放在哪一边。呃呃。

Oracle 开发人员倾向于将连接条件放入 WHERE 子句中,这似乎也是事实(再次如 The King 所说)。

-杰米特

Both will behave the same (as The King said). Personally I prefer the INNER/OUTER/LEFT JOIN syntax because its more intuitive/explicit. When you get into LEFT JOINs with join conditions in the WHERE clause then you have to get into using plus signs and then you have to remember which side to put them on. Urgghh.

It also seems (again as The King said) to be true that Oracle devs favour putting the join conditions into the WHERE clause.

-Jamiet

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文