Solved

Whats the difference between an INNER JOIN and a WHERE clause

Posted on 2014-10-11
7
96 Views
Last Modified: 2014-10-17
If I have
From
table Sales A
INNER JOIN table Salespeople B
ON
A.SalesID = B.SalesID

Then what are the pro/cons of doing the below instead
table Sales A, table SalespeopleB
Where
A.SalesID = B.SalesID
0
Comment
Question by:upobDaPlaya
  • 3
  • 2
  • 2
7 Comments
 
LVL 21

Expert Comment

by:pinaldave
Comment Utility
For inner join there is no difference if you put condition in where or join statement.

It differs for outer join.
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 250 total points
Comment Utility
a where clause is to filter out rows that you don't need.

Join is used to get data from other tables.

if you use a INNER join, that means that the link to the second must return data in order for the data of the first table to be returned.

a LEFT (or RIGHT) join does not filter out.
0
 

Author Comment

by:upobDaPlaya
Comment Utility
Which is more efficient...
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
they are different. If you can avoid going to the second table, it will be more efficient but sometimes you don't have all the data in the first table to filter out unwanted rows
0
 
LVL 21

Assisted Solution

by:pinaldave
pinaldave earned 250 total points
Comment Utility
Both will give you the same performance in the case of SQL Server when you use INNER JOIN.
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
I looked back at your 2 queries. The second one is using the old syntax.

As said by pinaldave, in this very specific case, both queries will perform exactly the same. If you check the Execution plan for both queries (from SSMS), you would find that the SQL engine transforms the second query in the same format as the first one.
0
 

Author Closing Comment

by:upobDaPlaya
Comment Utility
Thanks was always wondering on the above so thanks for answering
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now