Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 right join returns same results as left join

Author  Topic 

stringchopper
Starting Member

3 Posts

Posted - 2015-02-05 : 04:22:34
Hi,
Why does this right join return the same results as using a left (or even a full join)?

There are 470 records in Account, and there are 1611 records in Contact. But any join returns 793 records.

TIA!


select Contact.firstname, Contact.lastname, Account.[Account Name]
from Contact
right join Account
on Contact.[Account Name] = Account.[Account Name]
where Contact.[Account Name] = Account.[Account Name]


Regards, stringchopper

jleitao
Posting Yak Master

100 Posts

Posted - 2015-02-05 : 07:41:48
Why you need the "where"? With the "where" you just get the records that exists in both tables. Is that you need?

------------------------
PS - Sorry my bad english
Go to Top of Page

stringchopper
Starting Member

3 Posts

Posted - 2015-02-05 : 07:44:53
Thanks!


Regards, stringchopper
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-02-05 : 08:51:57
Actually, the 'where' clause functions differently in an outer join. Recall that in an outer join (left or right) rows that are not matched are returned with nulls on the left or right side. Then the where clause takes over and filters the results. The way this query is written, the combination of right join and where effectively turns the right join into an inner join
Go to Top of Page
   

- Advertisement -