Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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'
Posted
Updated 25-May-15 23:33pm
v2

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
 
Share this answer
 
There is no difference. The first one is old standered.

Reference:http://www.sqlservercentral.com/Forums/Topic262270-8-1.aspx[^]
 
Share this answer
 
Comments
Prabhani Panamulla 26-May-15 6:12am    
thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900