Solved

SQL inner vs left - precedence

Posted on 2013-12-20
1
798 Views
Last Modified: 2013-12-20
Hi,
 In MS SQL 2008, I am looking at a sample code like below:

Select *
from table1  t1 inner join table2 t2 on t1.id = t2.id

inner join table3 t3 on t1.id = t3.id

left join table4 t4 on t1.id = t4.id


I wanted to understand which join takes precedence:
1. Do all the three inner join execute first and then the resultset is left joined to the last table? In this case, the precedence is by virtue of which join is written first?

2. Inner joins take precedence over left join , regardless of in which order they are submitted?

3. Left join takes precedence over the inner join?

thx
0
Comment
Question by:LuckyLucks
1 Comment
 
LVL 10

Accepted Solution

by:
PadawanDBA earned 500 total points
Comment Utility
Join order evaluates left to right.  The result of the previous join is the left input to the next join.  Where this can introduce unintended consquences is when you have an outer join before an inner join and then you join to the table that was outer joined.  If there are null values that are preserved from the outer join and those values are used to join another table via an inner join, they will be filtered out.  You can get around this by parenthetically grouping your joins together to force the inner join to be evaluated before the outer join.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

8 Experts available now in Live!

Get 1:1 Help Now