Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g3NEE-0006eB-Q5 for pgsql-sql@arkaria.postgresql.org; Fri, 21 Sep 2018 15:20:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g3NEB-0002DO-Pq for pgsql-sql@arkaria.postgresql.org; Fri, 21 Sep 2018 15:20:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g3NEB-0002Cw-JH for pgsql-sql@lists.postgresql.org; Fri, 21 Sep 2018 15:20:19 +0000 Received: from hub.ringways.co.uk ([88.211.105.30] helo=ringways.co.uk) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g3NE9-00010o-5U for pgsql-sql@lists.postgresql.org; Fri, 21 Sep 2018 15:20:19 +0000 Received: from eddie.ringways.co.uk ([10.1.1.115]) by ringways.co.uk with esmtp (Exim 4.90_1) (envelope-from ) id 1g3NE8-0002Nc-8j; Fri, 21 Sep 2018 16:20:16 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@lists.postgresql.org Subject: Re: select where not in () fails Date: Fri, 21 Sep 2018 16:20:16 +0100 User-Agent: KMail/1.9.10 Cc: Pavel Stehule References: <201809211608.41086.gary.stainburn@ringways.co.uk> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201809211620.16084.gary.stainburn@ringways.co.uk> X-Spam-Score: -50.7 (--------------------------------------------------) X-Spam-Report: Spam detection software, running on the system "ollie2.ringways.co.uk", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see Gary Stainburn for details. Content preview: On Friday 21 September 2018 16:11:17 Pavel Stehule wrote: > maybe some value emp_u_id from employees is NULL. It is expected behave > > http://blog.9minutesnooze.com/sql-not-in-subquery-null/ > > Regards > > Pavel [...] Content analysis details: (-50.7 points, 15.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -50 ALL_TRUSTED Passed through trusted hosts only via SMTP 0.1 SCORE_RCPTS Adding score for each recipient 0.1 SCORE_RCPTS Adding score for each recipient -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 1.0 RING_SAFE No description available. List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Friday 21 September 2018 16:11:17 Pavel Stehule wrote: > maybe some value emp_u_id from employees is NULL. It is expected behave > > http://blog.9minutesnooze.com/sql-not-in-subquery-null/ > > Regards > > Pavel Thanks for this. As I said in my description, some values will be NULL. I just thought that these would not be included in the select. I did not think that it would stop the subselect from working users=# select count(u_id) from users where u_id not in (select distinct emp_u_id from employees where emp_u_id is not null); count ------- 393 (1 row) users=#