SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 difference between on & where clause in left join
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

learning_grsql
Posting Yak Master

230 Posts

Posted - 10/09/2012 :  11:07:02  Show Profile  Reply with Quote
The following two similar codes which I thought same produces two different outputs.

I wonder what the different is then between them.

select personid from table1 t1
left join table2 t2
on t1.personid = t2.personid and t2.personid is null
where date between '21020801' and '20120805' and t1.personid like '95*'


second code :

select personid from table1 t1
left join table2 t2
on t1.personid = t2.personid 
where date between '21020801' and '20120805' and t1.personid like '95*' and t2.personid is null


Edited by - learning_grsql on 10/10/2012 12:37:14

xhostx
Constraint Violating Yak Guru

USA
277 Posts

Posted - 10/09/2012 :  11:58:16  Show Profile  Reply with Quote
The First will show data from Table1 with respect to the referencing data from Table1 to Table2.
Second will Show data from Table1 BUT excluding the the JOIN data.

Here's a good example:
http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins


--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

learning_grsql
Posting Yak Master

230 Posts

Posted - 10/09/2012 :  12:41:11  Show Profile  Reply with Quote
The first one still seems confusing. The second one it seems I have got it now. Thank you very much. Very nice examples with images and pictures.
Go to Top of Page

xhostx
Constraint Violating Yak Guru

USA
277 Posts

Posted - 10/09/2012 :  13:42:44  Show Profile  Reply with Quote
you are welcome

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000