加入三个SQL表时,以下两种方式有什么不同? [英] what is the different between below two ways when join three SQL tables?

查看:106
本文介绍了加入三个SQL表时,以下两种方式有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个表SalesPerson,客户和订单

我通过使用join而不是来自以下查询得到相同的结果。任何人都可以解释一下,以下两种方式的差异和相似之处是什么?如果我们可以在没有加入的情况下做同样的事情,为什么要加入?



1)选择s.name

来自SalesPerson s,Orders o,Customer c

其中s.sid = o.sid和

c.cid = o.cid和

c .name ='Samsonic'



2)从订单中选择s.name



内部加入SalesPerson s

s.sid = o.sid

内部加入客户c

c.cid = o.cid

其中c.name ='Samsonic'

解决方案

您好,



这是个不错的问题。



两个查询的唯一区别就是性能。



如果你使用JOIN语句那么它然后会给WHERE语句提供更快的结果。



我试图在拥有大量数据的数据库中执行这两种查询,我注意到执行时间差异很大。 br />


我想,如果我们使用WHER E条件然后第一个SQL将获取所有数据,然后应用WHERE条件。如果我们使用JOIN语句,则SQL将仅考虑满足ON关键字条件的数据。



但是,区别仅在于SQL查询的性能。



请分享您的想法。



谢谢

Advay Pandya

没有区别。第一个是旧的standered。



参考: http:// www。 sqlservercentral.com/Forums/Topic262270-8-1.aspx [ ^ ]


I have 3 tables SalesPerson, Customer and Orders
I got the same result from below queries by using join and not. Can anyone please explain , what are the differences and similarities of below two ways? Why join if we can do the same thing without join?

1) select s.name
from SalesPerson s, Orders o, Customer c
where s.sid = o.sid and
c.cid = o.cid and
c.name = 'Samsonic'

2) select s.name
from Orders o
Inner Join SalesPerson s
on s.sid = o.sid
Inner Join Customer c
on c.cid = o.cid
where c.name = 'Samsonic'

解决方案

Hello,

it's nice question.

The only difference in both of the query is performance.

If you use JOIN statement then it will give faster result then WHERE statement.

I tried to execute both kind of queries in a database having huge amount of data and I noticed much difference in execution time.

I think, if we use WHERE condition then first SQL will fetch all the data and then apply WHERE condition. and If we use JOIN statement then SQL will consider only data which satisfy the condition in ON keyword.

But, the difference is only performance of SQL queries.

Please share your thoughts on this.

Thanks
Advay Pandya


There is no difference. The first one is old standered.

Reference:http://www.sqlservercentral.com/Forums/Topic262270-8-1.aspx[^]


这篇关于加入三个SQL表时,以下两种方式有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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