Re: [GENERAL] Difference between ON and WHERE in JOINs

2012-09-19 Thread Gavin Flower
On 20/09/12 03:08, Merlin Moncure wrote: On Tue, Sep 18, 2012 at 7:47 PM, David Johnston wrote: >On Sep 18, 2012, at 20:21, Jean-Christophe Boggio wrote: > >>I'm looking for an article that explains the difference between these constructs IN POSTGRESQL (the rules seem to differ from one DB

Re: [GENERAL] Difference between ON and WHERE in JOINs

2012-09-19 Thread David Johnston
Comments embedded between > > David, > > Thanks for the verbose explanations, really useful. > > However, in my case : > - type is never NULL Assuming you mean the "og.type" (i.e., the right-side of the join) even though the column

Re: [GENERAL] Difference between ON and WHERE in JOINs

2012-09-19 Thread Jean-Christophe Boggio
David, Thanks for the verbose explanations, really useful. However, in my case : - type is never NULL - there are no lines from uidinoldgroups that match the "FROM ldap" join. But I think I got it : drop table if exists tmpA; drop table if exists tmpB; create temp table tmpA (name varchar); in

Re: [GENERAL] Difference between ON and WHERE in JOINs

2012-09-19 Thread David Johnston
> I have this query working : > select profil,count(og.name) > from ldap l > left join uidinoldgroups ug on l.uid=ug.uid left join oldgroups og on > og.id=ug.idgroupe and og.rne='0410030k' and og.type='g' > where l.profilgeneral='P' > and l.rne='0410030k' > group by l.profil > > But if I put : >

Re: [GENERAL] Difference between ON and WHERE in JOINs

2012-09-19 Thread Kevin Grittner
Merlin Moncure wrote: > By having the filtering in the where clause, the intended purpose > of the left join, to return every row of foo, is being defeated > and the join will behave like an inner join. The right way to do > it is: > > SELECT * FROM foo LEFT JOIN BAR ON foo.id = bar.id AND bar

Re: [GENERAL] Difference between ON and WHERE in JOINs

2012-09-19 Thread Jean-Christophe Boggio
Le 19/09/2012 17:08, Merlin Moncure a écrit : SELECT * FROM foo LEFT JOIN BAR ON foo.id = bar.id AND bar.col = 'something'; The difference here is that the filtering is now happening at join time where the left join semantics are playing: always return foo and return bar rows if and only if the

Re: [GENERAL] Difference between ON and WHERE in JOINs

2012-09-19 Thread Jean-Christophe Boggio
Le 19/09/2012 02:47, David Johnston a écrit : > There is no difference in your example. Conceptually though I > suggest using only table-table conditions in an ON clause and placing > any table-value conditions into the where. This is how I use it usually. > The main time you get differences is

Re: [GENERAL] Difference between ON and WHERE in JOINs

2012-09-19 Thread Merlin Moncure
On Tue, Sep 18, 2012 at 7:47 PM, David Johnston wrote: > On Sep 18, 2012, at 20:21, Jean-Christophe Boggio > wrote: > >> I'm looking for an article that explains the difference between these >> constructs IN POSTGRESQL (the rules seem to differ from one DB to another) : >> >> SELECT A.* >> FROM

Re: [GENERAL] Difference between ON and WHERE in JOINs

2012-09-18 Thread David Johnston
On Sep 18, 2012, at 20:21, Jean-Christophe Boggio wrote: > I'm looking for an article that explains the difference between these > constructs IN POSTGRESQL (the rules seem to differ from one DB to another) : > > SELECT A.* > FROM A > JOIN B ON a.id=b.id AND A.somefield='somevalue' > > and >

[GENERAL] Difference between ON and WHERE in JOINs

2012-09-18 Thread Jean-Christophe Boggio
I'm looking for an article that explains the difference between these constructs IN POSTGRESQL (the rules seem to differ from one DB to another) : SELECT A.* FROM A JOIN B ON a.id=b.id AND A.somefield='somevalue' and SELECT A.* FROM A JOIN B ON a.id=b.id WHERE A.somefield='somevalue' I have