On Sun, 13 Nov 2005, Steve SAUTETNER wrote: > Hi, > > I have a table named "famille" whose structure and content is : > > famille_code | famille_mere_famille_code | famille_libelle | > famille_niveau > --------------+---------------------------+-------------------+------------- > --- > 000000 | | Mhre |
Is that a NULL famille_mere_famille_code? > The first col is the family id and the second is the mother family id. > I would get a list of all families that are never in the col n?2, so > the families that aren't node but leaf. > > The query, i made was "SELECT * FROM famille WHERE famille_code NOT IN > (SELECT DISTINCT famille_mere_famille_code FROM famille);" > > But the DB returns 0 records instead of 15. If i use a list instead of a > subquery it works normaly but it's not easy to manage it like this. > > So if anyone can help me please ... In the case where the subselect returns a NULL, the behavior of IN and NOT IN is rather unfortunate. A NOT IN B is basically NOT(A IN B) and A IN B is basically A =ANY B IIRC. However, A=ANY B only returns false if A = Bi returns false for all Bi contained in B and A = NULL returns unknown, not false, so NOT IN cannot return true if the subselect contains a NULL. If that is a null above, probably the best solution is to exclude NULLs from the subselect results. ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq