X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D4C649DCBBC for ; Tue, 6 Dec 2005 10:58:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23124-09 for ; Tue, 6 Dec 2005 10:58:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 5DD6D9DCB9C for ; Tue, 6 Dec 2005 10:58:09 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jB6EwBCp000165; Tue, 6 Dec 2005 09:58:11 -0500 (EST) To: mario.splivalo@mobart.hr cc: pgsql-sql@postgresql.org Subject: Re: JOIN query not working as expected In-reply-to: <1133878084.8161.22.camel@ekim> References: <1133878084.8161.22.camel@ekim> Comments: In-reply-to Mario Splivalo message dated "Tue, 06 Dec 2005 15:08:03 +0100" Date: Tue, 06 Dec 2005 09:58:11 -0500 Message-ID: <164.1133881091@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.003 required=5 tests=[AWL=0.003] X-Spam-Score: 0.003 X-Spam-Level: X-Archive-Number: 200512/40 X-Sequence-Number: 23582 Mario Splivalo writes: > Now I want all services which didn't have any messages within certain > period: > pulitzer2=# select * from services where id not in (select distinct > service_id from messages where receiving_time between '2005-10-01' and > '2005-10-30'); > (0 rows) > Why is that? Probably, you've got some NULLs in the messages.service_id column ... try excluding those from the sub-select. regards, tom lane