473,516 Members | 3,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7348
Atli
5,058 Recognized Expert Expert
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 Recognized Expert Specialist
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 Recognized Expert Expert
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
3195
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 to progress according to the best one for the job...which do you think?
2
3324
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 the user. I want that cookie should get deleted when user closes the browser without signing out. I think it is done in global.asa file . But i...
3
312
by: Sam Huang | last post by:
Hello, In a neutral perspective, which one is better? Regards, Sam Hwang
12
3202
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
2
2884
by: monkeydragon | last post by:
Which is better, using ReadFile/WriteFile or use fstream?
33
2525
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
22543
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 only where they match. Also sugest me which one is optimal in Inner Join and Where clause.
12
13158
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
2614
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 using subqueries (I think I happen to think that way more easily than join way :)) but I see others making use of joins all the time. May be that they...
1
5059
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 outer and inner join with some basic definition and example plzz..and also unique key. thanks, Pradeep
0
7574
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7136
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5106
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3265
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3252
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.