OUTER JOIN Filter by WHERE or ON Clauses ?!

If you would like to filter a RIGHT OUTER JOIN, e.g.

Table_1 RIGHT OUTER JOIN Table_2

then you have to put Table_1 columns in ON clause and Table_2 in WHERE clause, e.g.

Table_1 RIGHT OUTER JOIN Table_2 
ON Table_1.num = Table_2.num
AND Table_2.name = "Ahmed"
WHERE Table_1.name = "Ali"

If you swapped it or put all conditions in WHERE clause then it is as if you are doing INNER JOIN.

Resource: WHERE conditions on a LEFT JOIN

Advertisements

About Ahmed

Software craftsman, programmer, developer, system/business analyst, DBA and PM.
This entry was posted in Databases, Programming, SQL-Server, T-SQL and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s