473,424 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,424 software developers and data experts.

Which join is better, inner join or equi join

While joining like the below,

Expand|Select|Wrap|Line Numbers
  1. select * from EMPLOYEE e , position p where 
  2. e.empid=p.empid
  3.  
  4. select  * from EMPLOYEE e inner join position p where on e.empid=p.empid
  5.  
performance wise, which one is better, and why?

I didn't really understand the difference, some are saying 1st case is not a proper join. is that true?
Why it is not good.
Oct 25 '10 #1
3 7342
Atli
5,058 Expert 4TB
Hey.

jagadeesh kumar: I didn't really understand the difference, some are saying 1st case is not a proper join. is that true?
Not it's not true. It is a proper join, just a very "wide" join.

When you specify a list of table names, e.g: FROM tbl1, tbl2, tbl3, it is the equivelant of using a JOIN without an ON clause. - The result is the Cartesian product of the tables (that is: each row in all tables is joined with every row in all the other tables), which in most cases will result in a rather huge result set. The WHERE clause is then applied to that massive result set to get you your results.

Specifying the ON clause will cause MySQL to choose the rows for the joined set more carefully, resulting in a smaller result. The filters are applied before the joined set is compiled, which means the massive result set is never created.

I do not know exact details about the speed gains -- MySQL may well employ methods to reduce the loss of the Cartesian result set -- but it is generally advisable to use an ON clause.

Just to clarify, this query:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbl1, tbl2
  2. WHERE tbl1.id = tbl2.id
  3.  
is exactly equivalent to this query:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbl1 JOIN tbl2
  2. WHERE tbl1.id = tbl2.id
  3.  
And both of those should rather be written like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbl1
  2. JOIN tbl2 ON tbl1.id = tbl2.id
  3.  

Also note that JOIN, INNER JOIN and CROSS JOIN are all exactly the same thing. The reason why they all exists, yet are all the same, is to comply with the standards and to provide compatibility with other SQL systems.
Oct 25 '10 #2
ck9663
2,878 Expert 2GB
If you have the necessary index, it should not matter that much. And for INNER JOIN, the syntax #1 should work perfectly. However, for other type of joins, you might need to adjust the compatibility of your server.

The syntax #2 is more based on ANSI Standards.

JOIN, INNER JOIN, CROSS JOIN exists because they all work differently. Although a JOIN and INNER JOIN are the same, it's only because INNER is the default join if nothing is specified. CROSS JOIN is designed to produce a produce a Cartesian Product, by default. Unless you specify a WHERE condition, which now becomes similar to INNER JOIN. A CROSS JOIN with a WHERE condition is a filtered Cartesian Product. An INNER JOIN is a filtered result even before it goes to the Cartesian Product. Using an INNER JOIN is also safer than CROSS JOIN if the intention is to do an INNER JOIN. This is because, a missing condition in INNER JOIN will not work, while a missing condition in CROSS JOIN will work but will produce unintended results...

Here's a good article I found...

Happy Coding!!!

~~ CK
Oct 25 '10 #3
Atli
5,058 Expert 4TB
ck9663: JOIN, INNER JOIN, CROSS JOIN exists because they all work differently.
This.

Ignore what I said earlier. I had MySQL in mind when I wrote that. (I could have sworn this was in the MySQL forum when I first read it! :P)
Oct 25 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jason | last post by:
If you are sending out bulk emails in the range of 800 to 1000 per day which component is better: 1. ASPEmail 2. CDO ....and further, do they also BOTH use a SEND TO QUEUE option. I wish...
2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
3
by: Sam Huang | last post by:
Hello, In a neutral perspective, which one is better? Regards, Sam Hwang
12
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
2
by: monkeydragon | last post by:
Which is better, using ReadFile/WriteFile or use fstream?
33
by: Protoman | last post by:
Which is better for general-purpose programming, C or C++? My friend says C++, but I'm not sure. Please enlighten me. Thanks!!!!!
3
by: Smita Kashyap | last post by:
What is the main difference between Full Join and Inner Join in SQl Server 2005 ? As inner join retrive all records that match certain condition, similiary in full join will rreturn all records...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
2
theGeek
by: theGeek | last post by:
I always wonder which one of join or subquery should I be using to solve a particuar problem so that I get the correct result set in minimum time. It usually happens that I can write a query quickly...
1
pradeepjain
by: pradeepjain | last post by:
Hii guys, I might be silly to ask this ques..but seriously i did not understand the outer join and inner join in mysql site.i understood left and right join also. can some one explain...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.